Merge two pandas dataframe

I got the error below when merging two dataframes: df1 = df1.merge(df2,“left”,left_on=‘Name’,right_on=‘Name’, indicator=True, validate=‘many_to_one’)

NotImplementedError: Dtype category not understood.

Can anybody explain?

Hi @cadasa,

Your question is more related to pandas than streamlit at first glance. Based on the error, I doubt, if it has anything to do with merging dataframes. The issue is that streamlit does not know how to display columns with the type category. Most likely you’re getting that error with st.dataframe(df1) ?

If so, you can eliminate this error by converting the category columns to string as follows:
convert_dict = {
x: ‘str’ for x in df1.select_dtypes(‘category’).columns}
st.dataframe(df1.astype(convert_dict))

Hope this helps,

Dinesh

1 Like

Yes, when I used “indicator=True” in the merging it created a column of type “category” that streamlit failed to handle.

Thanks for your explanation!