mardi 30 mars 2021

Python Dataframe Conditional If Statement Using pd.np.where Erroring Out

I have the following dataframe:

count   country year    age_group   gender  type
7       Albania 2006    014         f       ep
1       Albania 2007    014         f       ep
3       Albania 2008    014         f       ep
2       Albania 2009    014         f       ep
2       Albania 2010    014         f       ep

I'm trying to make adjustments to the "gender" column so that 'f' becomes 'female' and same for m and male.

I tried the following code:

who3['gender'] = pd.np.where(who3['gender'] == 'f', "female")

But it gives me this error:

enter image description here

Now when I try this code:

who3['gender'] = pd.np.where(who3['gender'] == 'f', "female", 
                 pd.np.where(who3['gender'] == 'm', "male"))

I get error below:

enter image description here

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire