1.list
1,set 不能保证顺序
new_list = list(set(old_list))
2,循环
new_list = []
for value in old_list:
if value not in new_list:
new_list.append(value)
3,字典(推荐)可以保证顺序
new_list = list(dict.fromkeys(old_list))
2.dataframe
1,series
df = pd.DataFrame({'a':[1,2,3,4,5,4,3,2,1]})
df_1 = df.drop_duplicates()
df_2 = df.drop_duplicates(keep=False)
keep = False 是指重复的一个都不要
image.png
2,dataframe
df = pd.DataFrame({'a':[1,2,3,4,5,4,3,2,1],'b':list(range(9))})
df_1 = df.drop_duplicates()
df_2 = df.drop_duplicates(keep=False)
df_3 = df.drop_duplicates(['a'])
df_4 = df.drop_duplicates(['a','b'])
不加列名默认是全部.png
可加多个列名.png
网友评论