[英]Compare two data frames and return the value
I am new to programming and would like to get some suggestions on the given question.我是编程新手,想就给定问题获得一些建议。
DF_1 = r'H:\test\Output.xlsx' DF_1 = r'H:\test\Output.xlsx'
Object ![]() |
Code![]() |
Word![]() |
A![]() |
B![]() |
C ![]() |
D ![]() |
E![]() |
---|---|---|---|---|---|---|---|
AXe![]() |
31001 ![]() |
funktion![]() |
GFK ![]() |
house![]() |
1010 ![]() |
100 ![]() |
100 ![]() |
AY![]() |
31001 ![]() |
Start![]() |
GFK ![]() |
hotel![]() |
1020 ![]() |
200 ![]() |
200 ![]() |
DF_2 = r'H:\test\input.xlsx' DF_2 = r'H:\test\input.xlsx'
Obj![]() |
AB ![]() |
BC![]() |
CD![]() |
EF![]() |
GH![]() |
---|---|---|---|---|---|
0 ![]() |
31001 ![]() |
0 ![]() |
0 ![]() |
0 ![]() |
1010 ![]() |
0 ![]() |
31001 ![]() |
0 ![]() |
0 ![]() |
0 ![]() |
1020 ![]() |
I would like to compare these 2 excel files and append the ouput to the columns in the excel_2.我想比较这 2 个 excel 文件和 append 输出到 excel_2 中的列。
output: output:
Obj![]() |
AB ![]() |
BC![]() |
CD![]() |
EF![]() |
GH![]() |
---|---|---|---|---|---|
AXe![]() |
31001 ![]() |
funktion![]() |
GFK ![]() |
house![]() |
1010 ![]() |
AY![]() |
31001 ![]() |
Start![]() |
GFK ![]() |
hotel![]() |
1020 ![]() |
It is a matter of simple merge.这是一个简单的合并问题。 However, you'll need to rename the columns later.
但是,您稍后需要重命名这些列。
out = pd.merge(df2['AB', 'GH'], df1, how='left', left_on=['AB', 'GH'], right_on=['Code', 'C'])
out.rename(columns={
'Object': 'Obj',
'Word': 'BC',
'A': 'CD',
'B': 'EF',
}, inplace=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.