繁体   English   中英

熊猫系列的元素操作

[英]Elementwise operation on pandas series

我有一个熊猫系列x与值123

我希望它有值的monkeygorilla ,和tarzan取决于值。

我想我应该做些类似的事情

values = ['monkey', 'gorilla', 'tarzan']

x = values[x - 1]

但这不起作用。 我猜这是因为它不能按元素操作。

dict与功能map

样品:

s = pd.Series([1,2,3])
print (s)  
0    1
1    2
2    3
dtype: int64

d = {1:'monkey',2:'gorilla',3:'tarzan'}
print (s.map(d))
0     monkey
1    gorilla
2     tarzan
dtype: object

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM