Reputation: 69
a = pd.Series([1,2,3,4,5])
a.replace({1:10 , 3:10 , 5:10})
Instead of repeating it each time , is there any way to combine keys to replace the values.
Upvotes: 0
Views: 35
Reputation: 863226
Use list:
b = a.replace([1,3,5], 10)
print (b)
0 10
1 2
2 10
3 4
4 10
dtype: int64
Upvotes: 2