1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
df1 = pd.DataFrame({'key':['KO','K1','K2','K3'], 'A':['AD','A1','A2','A3'], 'B':['B0','B1','B2','B3']}) df2 = pd.DataFrame({'key':['KO','K1','K2','K3'], 'C':['CD','C1','C2','C3'], 'D':['D0','D1','D2','D3']}) print(df1) print(df2) print(pd.merge(df1,df2,on='key')) print('----')
df3 = pd.DataFrame({'key1':['KO','K0','K1','K2'], 'key2':['KO','K1','K0','K1'], 'A':['AD','A1','A2','A3'], 'B':['B0','B1','B2','B3']}) df4 = pd.DataFrame({'key1':['KO','K1','K1','K2'], 'key2':['KO','K0','K0','K0'], 'C':['CD','C1','C2','C3'], 'D':['D0','D1','D2','D3']}) print(df3) print(df4) print(pd.merge(df3,df4,on=['key1','key2']))
|