热线电话:13121318867

登录
2021-03-23 阅读量: 713
如何用Python处理Excel中的重复行

image.png

Excel表中有两条重复记录,那么如何将其去除呢?

# 导入pandas包并重命名为pd
import pandas as pd
# 读取Excel中Sheet1中的数据
data = pd.DataFrame(pd.read_excel('test.xlsx', 'Sheet1'))
# 查看读取数据内容
print(data)
# 查看是否有重复行
re_row = data.duplicated()
print(re_row)
# 查看去除重复行的数据
no_re_row = data.drop_duplicates()
print(no_re_row)
# 查看基于[物品]列去除重复行的数据
wp = data.drop_duplicates(['物品'])
print(wp)
# 将去除重复行的数据输出到excel表中
no_re_row.to_excel("过滤重复行.xlsx")

输出结果
在这里插入图片描述

200.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据