subset=['凭证号'] 代表 表头 是凭证号这一列 keep='first' 代表留下遇到重复的第一行,inplace=Ture 代表删除所有重复行
import os
u='D:\\业务'
os.chdir(u)
f='副本管家婆凭证源文件.xls'
c='删除重复行后的文件.xlsx'
n='源格式'
import pandas as pd
# 读取Excel文件
a = pd.read_excel(f, sheet_name=n)
# 查找重复行
b = a.duplicated()
# 删除重复行
# a = a.drop_duplicates()
# 保存Excel文件
# a.to_excel(c, index=False)
data = a.drop_duplicates(subset=['凭证号'],keep='first',inplace=False)
data.to_excel(c,index=False)
方法二
subset=3 代表第三列
import pandas as pd
import csv
import xlwt,xlrd
l = list()
with xlrd.open_workbook(r'D:\yewu\student.xls') as read:
sheet = read.sheet_by_name('Sheet1')
for i in sheet:
l.append(i)
df = pd.DataFrame(l)
df.drop_duplicates(subset=3,inplace=True)
df.to_csv('afterdel.csv')