把这段加入上面的代码中
时间: 2024-03-27 19:38:37 浏览: 12
好的,这里是完整代码,包括计算不同内容的总数:
```
import pandas as pd
# 读取Excel文件
excel_file = r"C:\Users\Chenzhong_Zhou\Desktop\对比需求\list\GAFP list(1).xlsx"
df_excel = pd.read_excel(excel_file, sheet_name="GAFP")
excel_col = df_excel["GAFP"].drop_duplicates()
# 设置pandas的显示选项
pd.set_option('display.max_columns', None) # 显示所有列
pd.set_option('display.max_rows', None) # 显示所有行
pd.set_option('display.width', 1000) # 设置显示宽度为1000像素
pd.set_option('display.max_colwidth', 1000) # 设置每列的最大宽度为1000像素
# 读取CSV文件
csv_file = r"C:\Users\Chenzhong_Zhou\Desktop\对比需求\list\ServerGrpProjectList_export_1684484264572.csv"
df_csv = pd.read_csv(csv_file)
csv_col = df_csv["ProjectId"].drop_duplicates()
# 数据对比
if excel_col.equals(csv_col):
result = "数据一致"
else:
# 计算不同内容的总数
diff_count = len(excel_col[~excel_col.isin(csv_col)]) + len(csv_col[~csv_col.isin(excel_col)])
# 输出不同内容的详细信息
diff_excel = excel_col[~excel_col.isin(csv_col)]
diff_csv = csv_col[~csv_col.isin(excel_col)]
result = "数据不一致\n\nExcel文件中多出的数据:\n{}\n\nCSV文件中多出的数据:\n{}\n\n不同内容的总数:{}".format(
diff_excel, diff_csv, diff_count)
# 将结果写入txt文件
txt_file = r"C:\Users\Chenzhong_Zhou\Desktop\对比需求\list\txt001.txt"
with open(txt_file, "w", encoding="utf-8") as f:
f.write(result)
```
这样就能输出不同内容的总数了。