我有一个关注者DataFrame
:
from pandas import *
df = DataFrame({'foo':['a','b','c'], 'bar':[1, 2, 3]})
它看起来像这样:
bar foo
0 1 a
1 2 b
2 3 c
现在我想要这样的东西:
bar
0 1 is a
1 2 is b
2 3 is c
我怎样才能实现这个目标?
我尝试了以下方法:
df['foo'] = '%s is %s' % (df['bar'], df['foo'])
但它给了我一个错误的结果:
>>>print df.ix[0]
bar a
foo 0 a
1 b
2 c
Name: bar is 0 1
1 2
2
Name: 0
抱歉问了一个愚蠢的问题,但是这个pandas:在 DataFrame 中合并两列 https://stackoverflow.com/questions/10972410/pandas-combine-two-columns-in-a-dataframe对我没有帮助。
df['bar'] = df.bar.map(str) + " is " + df.foo
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)