0

In my dataset there is a column that contains yes-no values, so I want to change them into 1-yes and 0-no using lambda function.

Code:

df['columnname'] = df['columnname'].apply(lambda a:1 if a == 'Yes' else 0)

The problem is all of data in my dataset turns into 0. Where is the error?

gosiia
  • 65
  • 1
  • 6

1 Answers1

0

You can use df.replace:

new_label = {'columnname': {'yes': 1, 'no': 0}}
df.replace(new_label, inplace=True)
Jorgo
  • 62
  • 5