mercredi 28 avril 2021

Using if-condition in pandas to fill na values in pandas

I have some columns in df where one of the columns has a missing value. I need to fill them but only when the ColumnY has a False value.

Here is how df looks

A                 B                    C
Value             4                    True
v3                9                    True
v9                                     False
v0                4                    False

I have a dictionary which I am using to map the values in column B ... di_map

df['B'].map(di_map)

Here is how output should look

A                 B                    C
Value             4                    True
v3                9                    True
v9                New_Val              False
v0                New_Val              False

Aucun commentaire:

Enregistrer un commentaire