So I have a data frame like this.
df1 = pd.DataFrame({'period':['2021-02'], 'customer':['A'], 'product':['Apple'], 'sales_flag': ['Yes']})
df2 = pd.DataFrame({'period':['2021-03', '2021-04', '2021-04'], 'customer':['A', 'A', 'A'], 'product':['Banana', 'Apple', 'Tangerine'], 'feedback_flag': ['Yes', 'Yes', 'No']})
I want to join the data frame like this.
period customer product sales_flag feedback_flag
'2021-02' A Apple Yes NULL
'2021-02' A Banana NULL NULL
'2021-02' A Tangerine NULL NULL
'2021-03' A Apple NULL NULL
'2021-03' A Banana NULL Yes
'2021-03' A Tangerine NULL NULL
'2021-04' A Apple NULL Yes
'2021-04' A Banana NULL NULL
'2021-04' A Tangerine NULL No
My code like this. But it didn't work.
df3 = df1.merge(df2, on = ['period', 'customer', 'product'], how = 'outer')
Do you have any idea how to make it work?