学习笔记,仅供参考
参考文献:Python专题】去重和选择唯一值的函数drop_duplicates、unique
文章目录
- np.unique()
- set
- DataFrame.drop_duplicates()
- DataFrame.duplicated()
np.unique()
代码
test1 = [1, 10, 2, 5, 1, 9, 5]
np.unique(test1)
结果
array([ 1, 2, 5, 9, 10])
set
test2 = [1, 10, 2, 5, 1, 9, 5]
set(test2)
{1, 2, 5, 9, 10}
DataFrame.drop_duplicates()
代码
test3 = pd.DataFrame([[1, 2],
[3, 4],
[1, 2],
[4, 5],
[3, 4]])
test3.drop_duplicates()
结果
DataFrame.duplicated()
代码
test4 = pd.DataFrame([[1, 2],
[3, 4],
[1, 2],
[4, 5],
[3, 4]])
test4.duplicated()
结果