如何在熊猫中将多个键映射到单个值?

时间:2020-05-08 10:12:08

标签: python python-3.x pandas

a = pd.Series([1,2,3,4,5])
a.replace({1:10 , 3:10 , 5:10})

有什么方法可以代替组合键来替换值了?

1 个答案:

答案 0 :(得分:2)

使用列表:

b = a.replace([1,3,5], 10)
print (b)
0    10
1     2
2    10
3     4
4    10
dtype: int64