我有一个df和ID和Sell列。我想使用一个新销售列表来更新“销售”列(不是所有的RAW都需要更新,只是其中的一部分)。在我看到的所有示例中,值总是相同的,或者来自一列。在我的例子中,我有一个动态值
这就是我想要的:
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)
有什么想法吗? 提前谢谢
这将有效地工作,特别是对于大型文件:
假设'id'是字符串(如IDList中所述)&;不是您的df的索引
如果id是索引:
我所做的是使用IDlist&;销售名单及;然后使用iterrows()在df上循环
相关问题 更多 >
编程相关推荐