samedi 30 mai 2020

How to do pd.fillna() with condition

Am trying to do a fillna with if condition

Fimport pandas as pd
df = pd.DataFrame(data={'a':[1,None,3,None],'b':[4,None,None,None]})
print df

df[b].fillna(value=0, inplace=True) only if df[a] is None
print df


  a   b
0 1   4
1 NaN NaN
2 3   NaN
3 NaN NaN

##What i want to acheive

  a   b
0 1   4
1 NaN 0
2 3   NaN
3 NaN 0

Please help

Aucun commentaire:

Enregistrer un commentaire