Python入门5(pandas中merge中的参数how)

 1 import pandas as pd
 2 df1 = pd.DataFrame([[1,2,3],[1,10,20],[5,6,7],[3,9,0],[8,0,3]],columns=['x1','x2','x3'])
 3 df2 = pd.DataFrame([[1,2],[1,10],[1,3],[4,6],[3,9]],columns=['x1','x4'])
 4 print (df1)
 5 print (df2)
 6 df3 = pd.merge(df1,df2,how = 'left',on='x1')
 7 print (df3)
 8 df4 = pd.merge(df1,df2,how = 'right',on='x1')
 9 print (df4)
10 df5 = pd.merge(df1,df2,how = 'inner',on='x1')
11 print (df5)
12 df6 = pd.merge(df1,df2,how = 'outer',on='x1')
13 print (df6)

posted @ 2017-12-01 15:55 yuanninesuns 阅读(...) 评论(...) 编辑 收藏