【发布时间】:2020-10-26 21:07:01
【问题描述】:
尝试执行此 excel 比较脚本时遇到上述错误,请帮助。 该脚本的目标是能够比较 excel 并突出显示差异,如果您能建议我如何包含主键之类的列,那就太好了
df1=pd.read_excel('File1.xlsx')
df2=pd.read_excel('File2.xlsx')
df1.equals(df2)
comparison_values = df1.values == df2.values
print (comparison_values)
import numpy as np
rows,cols=np.where(comparison_values==False)
for item in zip(rows,cols):
df1.iloc[item[0], item[1]] = '{} --> {}'.format(df1.iloc[item[0], item[1]],df2.iloc[item[0], item[1]])
df1.to_excel('./Excel_diff.xlsx',index=False,header=True)
python3 compare_excels.py
compare_excels.py:8: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.
comparison_values = df1.values == df2.values
False
Traceback (most recent call last):
File "compare_excels.py", line 12, in <module>
rows,cols=np.where(comparison_values==False)
ValueError: not enough values to unpack (expected 2, got 1)```
【问题讨论】: