I want to merge two data frames and make a subset of the columns rows in the output dataframe. The two tables are as follows
Table Stk
stk = pd.DataFrame({'code':['A121','H812','Z198'],'01-05-2021':[4,2,6],'02-05-2021':[1,3,2],'03-05-2021':[12,13,12]})
Table Sup
sup = pd.DataFrame({'code':['A121','H812','S222'],'01-05-2021':[2,2,2],'03-05-2021':[5,5,5],'06-05-2021':[1,4,7]})
Output Table
Brief Explanation on how the Output table needs to be created:
- The output table needs to have a union of all date columns in stk table and sup table
- The output table also needs to have 2 rows for union of each code in both the tables
- The corresponding value from each table with respect to the code and date needs to assigned in the appropriate cell in the output table
- If value does not exist mark it as np.nan in the output table
I hope this is clear. Any suggestion or help regarding this will be greatly appreciated. I have tried using merge and an outer join on both the tables but that creates extra date columns. I am not sure how to create rows out of that.