I have two dataframes with identical column names and dtypes, similar to the following:
A object
B category
C category
The categories are not identical in each of the dataframes.
When normally concatinating, pandas outputs:
A object
B object
C object
Which is the expected behaviour as per the documentation.
However, I wish to keep the categorisation and wish to union the categories, so I have tried the union_categoricals across the columns in the dataframe which are both categorical. cdf and df are my two dataframes.
for column in df:
if df[column].dtype.name == "category" and cdf[column].dtype.name == "category":
print (column)
union_categoricals([cdf[column], df[column]], ignore_order=True)
cdf = pd.concat([cdf,df])
This is still not providing me with a categorical output.