我想通过连接两个列(float或int)来创建一个新列,如下所示:
你有更好的想法吗?
我觉得我的方法太过复杂了。
你有更好的想法吗?
我觉得我的方法太过复杂了。
a=pandas.Series([1,3,5,7,9])
b=pandas.Series([2,4,6,8,10])
c=pandas.Series([3,5,6,5,10])
abc=pandas.DataFrame({'a':a, 'b':b, 'c':c})
abc
a b c
0 1 2 3
1 3 4 5
2 5 6 6
3 7 8 5
4 9 10 10
abc['new']=pandas.Series(map(str,abc.iloc[:,0])).str.cat(pandas.Series(map(str,abc.iloc[:,1])), sep='::')
abc
a b c new
0 1 2 3 1::2
1 3 4 5 3::4
2 5 6 6 5::6
3 7 8 5 7::8
4 9 10 10 9::10
Jeff
现在是 pandas 的开发者。 - jezraelmap
更简单更快。但apply
更复杂。另外,如果使用.apply(axis=1)
,它会按行处理,速度也很慢。对于你的解决方案,不能使用map
,因为它只能用于一个列(Series
)。 - jezrael