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

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
1
0
关注作者
收藏
评论(0)
发表评论
暂无数据
推荐帖子
0条评论
0条评论

