After filling in nulls in all of my category
columns using the solutions from here and here, I was left with many nulls in many of my float columns. I thought a simple df.fillna(0.0, inplace = True)
would work, but, I get the error ValueError: fill value must be in categories
. I thought this error was only for category
type columns.
So,
I have many float columns and many category columns. I filled category columns by adding category "unknown" and then filling nulls by "unknown". Now, a simple
df.fillna(0.0, inplace = True)
should have worked. But, it does not.
A simple way to reproduce this problem is the following:
df = pd.DataFrame({"A": ["a"], "B":[np.nan] })
df['A'] = df['A'].astype('category')
df.fillna(0.0, inplace = True)
Please don't say that I can do:
df['A'].fillna(0.0, inplace = True)
I have many float columns, and I can't go one by one. I have to fill all the nulls in remaining columns by 0.0 in bulk. Rest assured, all the columns are float type, but, there could be additional category
columns, but, they don't have any nulls.
Appreciate any solutions.