My df1 data frame
df1
prod_cat_code prod_cat prod_sub_cat_code prod_subcat
1 Clothing 4 Mens
2 Footwear 1 Women
1 Clothing 3 Kids
My df2 data frame
df2
customer_Id prod_sub_cat_code prod_cat_code
268408 4 1
268408 1 1
268408 1 2
268408 3 1
268408 4 2
I want to replace df2
prod_subcat_code
withprod_subcat
from df1 ;I want to replace df2
prod_cat_code
withprod_cat
from df1 ;
Q: Do I need a dictionary and map the values or is there any alternative?
(df2.merge(df1[['prod_cat_code', 'prod_cat']], how='left') .merge(df1[['prod_sub_cat_code', 'prod_subcat']], how='left'))
throw merge error