I am trying to join two data tables together with different index lengths - one is a multi index and the other a range index of type int. I need to join another table with a much shorter index, and have the rows repeat where necessary and replace with NAN as would be replicated with a left join in sql.
I have the following production data table:
-------------------------------
Month Plant Product Production
-------------------------------
1 A AFS 11,212
TF1 9,005
AA1 21,656
B AA1 11,512
POD 6,550
2 A AFS 12,550
TF1 12,121
AA1 15,091
B AA1 16,212
POD 7,890
and the following price forecast data, monthly:
-------------------------------
Month Product Forecast Price
-------------------------------
1 AFS 0.91
AA1 6.66
TF1 11.90
POD 21.80
ZBR 0.61
TPO 0.88
2 AFS 1.12
AA1 7.42
TF1 12.56
I would like to have the following final table:
----------------------------------------------
Month Plant Product Production Forecast Price
----------------------------------------------
1 A AFS 11,212 0.91
TF1 9,005 11.90
AA1 21,656 6.66
B AA1 11,512 1.12
POD 6,550 etc
2 A AFS 12,550
TF1 12,121
AA1 15,091
B AA1 16,212
POD 7,890
I have tried using
pd.concat([df, fcast_df], join='inner', axis=0)
and df.merge(fcast_df, left_index=True, right_on='Product')
The first option yields nothing and the second unfortunately is not the result I am after as it does not account for the multi-indexing of the first dataframe i.e. join on both Month and Product.
Any help greatly appreciated