This is my code to compare difference between 2 xlsx files:
这是我比较2个xlsx文件之间差异的代码:
import pandas as pd
df1 = pd.read_excel('SnapshotID_Old.xlsx')
df2 = pd.read_excel('SnapshotID_New.xlsx')
difference = df1[df1 != df2]
print difference
It gives me this error:
它给了我这个错误:
ValueError: Can only compare identically-labeled DataFrame objects
What's missing?
少了什么东西?
1 个解决方案
#1
0
You probably solved this already, but as COLDSPEED said, you probably have different headers in your Excel.
您可能已经解决了这个问题,但正如COLDSPEED所说,您的Excel中可能有不同的标题。
You could try using eq
or ne
flexible comparison methods instead:
您可以尝试使用eq或ne灵活的比较方法:
import pandas as pd
df1 = pd.read_excel('SnapshotID_Old.xlsx')
df2 = pd.read_excel('SnapshotID_New.xlsx')
difference = df1[df1.ne(df2)]
print difference
#1
0
You probably solved this already, but as COLDSPEED said, you probably have different headers in your Excel.
您可能已经解决了这个问题,但正如COLDSPEED所说,您的Excel中可能有不同的标题。
You could try using eq
or ne
flexible comparison methods instead:
您可以尝试使用eq或ne灵活的比较方法:
import pandas as pd
df1 = pd.read_excel('SnapshotID_Old.xlsx')
df2 = pd.read_excel('SnapshotID_New.xlsx')
difference = df1[df1.ne(df2)]
print difference