从两张excel表中合并数据的熊猫

时间:2017-10-31 20:41:55

标签: python excel pandas

我正在尝试根据列值匹配两个excel表, 我开始编写这段代码:

import pandas as pd
transit = "C\\Users\\Taqwa\\Desktop\\dta_coded\\data.xlsx"
xlsx = pd.ExcelFile(transit)
df = pd.read_excel(xlsx,"201705_ch2m","zonUnsom163")

出现以下错误:

TypeError: list indices must be integers or slices, not str

1 个答案:

答案 0 :(得分:0)

如果您有两个具有相同列名的单独excel文件,则可以通过以下方法进行比较

import pandas as pd

df1 = pd.read_excel('file1.xlsx')
df2 = pd.read_excel('file2.xlsx')

diff = df1[df1!=df2]
print (diff)