本文介绍了 pandas 使用新值更新数据框行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本文件,已被df1 = pandas.read_csv(r'fruits.txt', sep=',')
I have a text file which has been read into pandas by df1 = pandas.read_csv(r'fruits.txt', sep=',')
item freshness 0 apple 2.2 1 pear 0.0以及一系列得出apple = 2.3
是否可以执行pandas.update,以便可以将数据框中的apple的freshness值更新为2.3?
Is it possible to do a pandas.update so that I can update the value of freshness for apple in the dataframe to 2.3?
推荐答案IIUC,您需要 loc :
IIUC you need loc:
apple = 2.3 print df['item'] == 'apple' 0 True 1 False Name: item, dtype: bool df.loc[df['item'] == 'apple', 'freshness'] = apple print df item freshness 0 apple 2.3 1 pear 0.0更多推荐
pandas 使用新值更新数据框行
发布评论