Reputation: 99
I would like to create a column called "target" which contains 0 value if name columns is "NaN" and 1 if it is non.
I did, like this:
df_opportunity['target'] = np.where(df_opportunity['name']=='NaN', '0', '1')
But it puts always 0
Any ideas?
Upvotes: 2
Views: 32
Reputation: 4482
I always found tricky the way to compare NaN
in pandas
. The appropriate would be:
df_opportunity['target'] = np.where(pd.isnull(df_opportunity['name']), '0', '1')
Upvotes: 2