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 columns for all values v of X
I obtain the frequency columns by performing an outer join, which introduces NaN values into the data frame. So df.fillna(0) worked perfectly until I discretized my original Dataset using data.cut(), where data is also a DataFrame. Now I receive the ValueError.
What I've tried so far:
for header in list(df):
if 'freq_' in header:
catcol = pd.Series(df[header], dtype='category')
catcol.cat.add_categories(0)
catcol.fillna(0)
cft[header] = catcol
This is supposed to take the frequency columns out of the DataFrame, convert them to categorical Seiries's so that I am allowed to introduce the new category, and apply fillna() before I overwrite the original column with the series. However, it still throws the exact same error. How do I do this better?