Reputation: 383
For all cells in my dataframe, I just want to replace whitespace or empty (not NAN) with 0. Tried the below, but doesn't work.
Thank you
df1 = df1.all(apply(lambda x: 0 if x == ' ' or x=='' else x))
Upvotes: 0
Views: 66
Reputation: 323226
Try with replace
df1 = df1.replace({' ':0,'':0})
or Change your function from apply to mask
df1 = df1.mask(df1.isin([' ', '']),0)
Upvotes: 4