I have a dataframe like :
ItemName Category
item1 cat1
item2 cat1
item3 cat1
item4 cat1
item5 cat2
item6 cat2
and one like:
CategoryName Element
cat1 element1
cat2 element2
I want to merge both dataframes into one, based on the category column, but now I have two columns having the categories. This would be the ideal result:
ItemName Category Element
item1 cat1 element1
item2 cat1 element1
item3 cat1 element1
item4 cat1 element1
item5 cat2 element2
item6 cat2 element2
But I have the result with duplicate of column Category and CategoryName. How to solve this duplicate issue when merging the dataframes? What I did for the merge:
result_df= df1.merge(
df2,
left_on='Category',
right_on='CategoryName',
how='inner')