我有一个包含ID和Sell两列的数据框。我想使用新的Sell列表来更新Sell列(不需要更新所有行 - 仅需要更新其中一些)。在我看到的所有示例中,值始终相同或来自某一列。而在我的情况下,我有一个动态值。
这是我想要的:
file = ('something.csv') # Has 300 rows
IDList= [['453164259','453106168','453163869','453164463'] # [ID]
SellList=[120,270,350,410] # Sells values
csv = path_pattern = os.path.join(os.getcwd(), file)
df = pd.read_csv(file)
df.loc[df['Id'].isin(IDList[x]), 'Sell'] = SellList[x] # Update the rows with the corresponding Sell value of the ID.
df.to_csv(file)
有什么想法吗? 提前感谢。