I have 2 dataframes that I want to be merged together.
Df1 : sales dataframe, only with sold products. if not sold, not there. ALL WEEKS 1 to 53 for 2019/2020/2021
Year   Week   Store   Article   Sales Volume
2019   11     SF      sku1      500
2021   16     NY      sku2      20
2020   53     PA      sku1      500
2021   01     NY      sku3      200
2019   11     SF      sku1      455
2021   16     NY      sku2      20
df2: is a stock dataframe. Entire product range, even if not sold, it appears. Only with stock at WEEK 16 for each 2019/2020/2021 year for each ALL products
Year   Week   Store   Article   Stock Volume
2019   16     SF      sku1      500
2021   16     NY      sku2      20
2020   16     PA      sku4      500
2021   16     NY      sku5      200
2019   16     SF      sku65      455
2021   16     NY      sku2000      20
                      ...
I have tried to merge both dfs by doing this (I wanted to get all Articles but the drawback is that I loose the other weeks):
merged = pd.merge(df1,df2, how = "right", right_on=["Article ID", "Year ID", "Week ID", "Store ID"], left_on=["Article", "Year", "Week", "Store"])
But I only get the sales value associated to week 16 stock and I lose all the other weeks.
So I tried a left join
merged = pd.merge(df1,df2, how = "left", right_on=["Article ID", "Year ID", "Week ID", "Store ID"], left_on=["Article", "Year", "Week", "Store"])
Now I have all the weeks but I am missing some products stocks
I need to keep ALL PRODUCTS of df2 while also keeping weeks of sales of df1. Is there a way to merge both dfs by keeping the entire stock depth and the entire sales weeks ?
Thanks for your help !!
 
     
    