Skip to content Skip to sidebar Skip to footer

Df.fillna() Throws Valueerror: Fill Value Must Be In Categories

I have a DataFrame df without specified Dtypes, which is a conditional frequency table where the headers are organized in the following way: Data Attributes excluding X | freq_v co

Solution 1:

As explained by Ben.T, cat.add_categories returns a new Series, so I need to change my code in the following way:

for header in list(df):
        if 'freq_' in header:
            catcol = pd.Series(df[header], dtype='category')
            catcol = catcol.cat.add_categories(0)
            catcol.fillna(0)
            cft[header] = catcol

Post a Comment for "Df.fillna() Throws Valueerror: Fill Value Must Be In Categories"