How to ignore NaN? when DataFrame formats data

df is a dataframe , in which there are some NaN values in df . The following code formats each column in turn (for example, changing money into a string that begins with a dollar sign, and the corresponding function is formatter_function ). How to ignore the nan value and not deal with it?

for col in df.columns:
    df[col] = formatter_function(df[col])
return df
Mar.24,2021

it is recommended that your formatter_function be modified to ignore NaN , thus simplifying the code

.
return df.apply(formatter_function) 

otherwise you can do this

return df.apply(lambda c: c[~np.isnan(c)].apply(formatter_function))
Menu