Reputation: 25
I am trying to replace values in a column, but for some reason one of the values is not changing. The three values are - 'xxx'
, 'aaa'
and 0
. The problem is with the zero.
This is part of the code I am using:
df['source'] = np.select(conditions, ['xxx', 'aaa'], default=0)
df['source'] = df['source'].replace({'xxx': 'xxx', 'aaa': 'aaa', 0: 'test'})
First I am using np.select
based on some conditions and since I cant put string value on default
, I want to replace the zero with another string. And I can't understand what I am doing wrong.
Upvotes: 0
Views: 50
Reputation: 454
0 may be "0" as a string. check for whitespaces as well. If the series "source" is an "object" then "0" is a string.
In this case:
df['source'] = df['source'].replace({'xxx': 'xxx', 'aaa': 'aaa', '0': 'test'})
Upvotes: 2