我试图编写一个python脚本,逐列比较两个excel文件。 我只编写了一个脚本来比较文件是否相同(即相同的形状、行和列),但我在已添加的其中一个文件中有一列(即在另一个文件中不存在),我不想比较它们。我该怎么做
这就是我用来比较两个文件是否完全相同的方法
import pandas as pd
#Reading two Excel Sheets
sheet1 = pd.read_csv("crystal.csv")
sheet2 = pd.read_csv("reformatted_crystal.csv")
# Iterating the Columns Names of both Sheets
for i,j in zip(sheet1,sheet2):
# Creating empty lists to append the columns values
a,b =[],[]
# Iterating the columns values
for m, n in zip(sheet1[i],sheet2[j]):
# Appending values in lists
a.append(m)
b.append(n)
# Iterating the list's values and comparing them
for m, n in zip(range(len(a)), range(len(b))):
if a[m] != b[n]:
print('Column name : \'{}\' and Row Number : {}'.format(i,m))
如果您不想永久删除它,也许您可以为sheet2数据帧使用temp
相关问题 更多 >
编程相关推荐