I have a dataframe column which has been discretized using pd.cut. While trying to work with an algorithm, requires me to do the following:
for k, v in dictMap.items():
df.loc[k, column] = v
This gives me an error:
<pre lang="Python">>ValueError: Cannot setitem on a Categorical with a new category, set the categories first
.
After discretizing, Column A contains values [1,2,3,4,5].
What I have tried:
After figuring out the datatype I have tried to convert the column dtype using:
df["A"] = df ["A"].apply(lambda x: x.cat.codes)
.
This now gives me the error:
AttributeError: long object has no attribute cat
.
print(df["A"])
outputs:
Name:A, Length 891, dtype:category
Categories(25, int64): [0<1<2<3...21<22<23<24]
My goal is to have this discretized column in the dataframe converted to the dtype int.