16-pandas数据归并几对几

import numpy as np
import pandas as pd
#1.一对一
df1=pd.DataFrame({"name":["A","B","C"],
                  "age":[30,32,33]})
df2=pd.DataFrame({"name":["A","B","C"],
                  "tall":[310,312,313]})
print(pd.merge(df1,df2))#一对一归并

#2.一对多
df3=pd.DataFrame({"name":["A","B","C"],
                  "type":["陕西","江西","江西"]})
df4=pd.DataFrame({"number":[1000,2000,3000],
                  "type":["陕西","江西","广西"]})
print(pd.merge(df3,df4))

#3.多对多
df5=pd.DataFrame({"area":["north","south","north"],
                  "type":["陕西","江西","江西"]})
print(pd.merge(df5,pd.merge(df3,df4)))

  

posted @ 2020-03-09 11:06  胡辣汤王子  阅读(167)  评论(0编辑  收藏  举报