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))
CodePudding user response:
Try with replace
df1 = df1.replace({' ':0,'':0})
or Change your function from apply to mask
df1 = df1.mask(df1.isin([' ', '']),0)