In [1]: import pandas as pd
...: a1=[1,2,3,4]
...: a2=[1,1,2,3]
...: df=pd.DataFrame({"a1":a1,"a2":a2})
In [2]: df.duplicated("a2") # 返回a2列是否重复,第一次出现重复的数据为False,其余为True
Out[2]:
0 False
1 True
2 False
3 False
dtype: bool
In [3]: df.drop_duplicates("a2") # 直接去掉重复数据
Out[3]:
a1 a2
0 1 1
2 3 2
3 4 3
Pandas DataFrame 去重
最新推荐文章于 2023-08-14 13:29:04 发布