---------------------整行去重---------------------------------------------------
# 导入pandas包并重命名为pd
import pandas as pd
# 读取Excel中Sheet1中的数据
data = pd.DataFrame(pd.read_excel("C:\\Users\\Thinkpad\\Desktop\\A.xls", '温度'))
# 查看读取数据内容
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("C:\\Users\\Thinkpad\\Desktop\\V.xls.xls")
---------------------按照其中某一列去重---------------------------------------------------
# 导入pandas包并重命名为pd
import pandas as pd
# 读取Excel中Sheet1中的数据
data = pd.DataFrame(pd.read_excel("C:\\Users\\Thinkpad\\Desktop\\A.xls", '温度'))
# 查看读取数据内容
print(data)
# 查看是否有重复行
re_row = data.duplicated()
print(re_row)
# 按照其中某一列去重
no_re_row = data.drop_duplicates(subset='时间')
print(no_re_row)
# 查看基于[物品]列去除重复行的数据
# wp = data.drop_duplicates(['物品'])
# print(wp)
# 将去除重复行的数据输出到excel表中
no_re_row.to_excel("C:\\Users\\Thinkpad\\Desktop\\V.xls.xls")
---------------------多列去重,保留最后出现值---------------------------------------------------
# 导入pandas包并重命名为pd
import pandas as pd
# 读取Excel中Sheet1中的数据
data = pd.DataFrame(pd.read_excel("C:\\Users\\Thinkpad\\Desktop\\A.xls", '温度'))
# 查看读取数据内容
print(data)
# 查看是否有重复行
re_row = data.duplicated()
print(re_row)
# 查看去除重复行的数据,保留最后出现的值
no_re_row = data.drop_duplicates(subset=['时间','设计编号'], keep='last')
print(no_re_row)
# 查看基于[物品]列去除重复行的数据
# wp = data.drop_duplicates(['物品'])
# print(wp)
# 将去除重复行的数据输出到excel表中
no_re_row.to_excel("C:\\Users\\Thinkpad\\Desktop\\V.xls.xls")