2024-04-18 17:53:56 发布
网友
我有一个pandas系列x,值为1,2或{}。在
x
1
2
我希望它有值monkey,gorilla,和{},具体取决于这些值。在
monkey
gorilla
我想我应该做点什么
values = ['monkey', 'gorilla', 'tarzan'] x = values[x - 1]
但它不起作用。我想这是因为它没有基本的运作方式。在
使用dict与函数^{}进行映射。在
dict
样品:
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
使用} 进行映射。在
dict
与函数^{样品:
相关问题 更多 >
编程相关推荐