所以我有一个这样的数据框
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']})
我想像这样连接数据帧
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
我的代码是这样的。但它不起作用
df3 = df1.merge(df2, on = ['period', 'customer', 'product'], how = 'outer')
你知道怎么做吗
根据独特的产品,尝试外部^{} 后跟^{} 到^{} ,然后^{} +^{} 填写期限和客户:
df3
:相关问题 更多 >
编程相关推荐