It is required to have a method that firstly checks the content of each cell of a dataframe and if the cell contains only spaces and nothing else then fills it with np.nan
. To do so, I have written the following method:
def white_space_replacer(df):
for i in list(df):
if not is_numeric_dtype(df[i]) and df[i].any().isspace():
df[i] = df[i].fillna(np.nan)
But it doesn't change anything.
What should be changed in the method to work properly?