pandas-22 数据去重处理

import numpy as np
import pandas as pd
from pandas import Series, DataFrame df = pd.read_csv('./demo_duplicate.csv')
print(df)
print(df['Seqno'].unique()) # [0. 1.] # 使用duplicated 查看 重复值
# 参数 keep 可以标记重复值 {'first','last',False}
print(df['Seqno'].duplicated())
'''
0 False
1 True
2 True
3 True
4 False
Name: Seqno, dtype: bool
''' # 删除 series 重复数据
print(df['Seqno'].drop_duplicates())
'''
0 0.0
4 1.0
Name: Seqno, dtype: float64
''' # 删除 dataframe 重复数据
print(df.drop_duplicates(['Seqno'])) # 按照 Seqno 来 去重
'''
Price Seqno Symbol time
0 1623.0 0.0 APPL 1473411962
4 1649.0 1.0 APPL 1473411963
'''
# drop_dujplicates() 第二个参数 keep 包含的值 有: first、last、False
print(df.drop_duplicates(['Seqno'], keep='last')) # 保存最后一个
'''
Price Seqno Symbol time
3 1623.0 0.0 APPL 1473411963
4 1649.0 1.0 APPL 1473411963
'''
05-11 11:07