pandas三列数关联匹配

import pandas as pd
data=pd.read_excel('20161002.xlsx')
D1=set(data.D201606)
D2=set(data.D201512)
D3=set(data.D201506)
D4=set(data.D201501)
D=list(D1&D2&D3&D4)


result=pd.DataFrame(columns=['NAME','R201606','R201512','R201506','R201501'])
i=0
for item in D:
    result.loc[i,'NAME']=item
    result.loc[i,'R201606']=list(data[data['D201606']==item].value1)[0]
    result.loc[i,'R201512']=list(data[data['D201512']==item].value2)[0]
    result.loc[i,'R201506']=list(data[data['D201506']==item].value3)[0]
    result.loc[i,'R201501']=list(data[data['D201501']==item].value4)[0]
    i=i+1
pd.DataFrame(result).to_excel(r"E:\Users\Desktop\结果.xlsx")    

你可能感兴趣的:(Python)