我有一个文本文件,已被读入 pandasdf1 = pandas.read_csv(r'fruits.txt', sep=',')
item freshness
0 apple 2.2
1 pear 0.0
以及一系列的计算,得出的结果是apple = 2.3
是否可以做一个pandas.update
这样我就可以更新的值freshness
for apple
在数据框中2.3
?
你需要的IIUCloc http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)