【发布时间】:2019-11-15 11:40:04
【问题描述】:
我正在尝试使用 python 脚本合并 excel.xlsx 中的 2 张工作表。我希望当 sheet1('CLASS') 与 sheet2('C_MAP') 匹配时,然后在 sheet1 或新工作表中的 CLASS 之后合并 DSC 和 ASC。
为了澄清这一点,我附上了我的 Excel 表格。
这是我的 Sheet1:
P_MAP Q_GROUP CLASS
0 ram 2 pink
1 4 silver
2 sham 5 green
3 0 default
4 nil 2 pink
它包含P_MAP,Q_GROUP,CLASS
这是我的 Sheet2:
C_MAP DSC ASC
0 pink h1 match
1 green h2 match
2 silver h3 match
它包含C_MAP,ASC,DSC
所以,我希望当 CLASS 与 C_MAP 匹配时,它应该添加 ASC 和 DSC,如果不匹配则添加 NA。
我想要的输出是这样的:
P_MAP Q_GROUP CLASS DSC ASC
0 ram 2 pink h1 match
1 4 silver h3 match
2 sham 5 green h2 match
3 0 default 0 NA
4 nil 2 pink h1 match
【问题讨论】:
标签: excel python-3.x pandas