Python处理重复值的方法有以下几种:
lst = [1, 2, 3, 3, 4, 4, 5]
lst = list(set(lst))
print(lst) # 输出 [1, 2, 3, 4, 5]
lst = [1, 2, 3, 3, 4, 4, 5]
lst = [x for i, x in enumerate(lst) if x not in lst[:i]]
print(lst) # 输出 [1, 2, 3, 4, 5]
from collections import Counter
lst = [1, 2, 3, 3, 4, 4, 5]
counter = Counter(lst)
lst = [x for x in counter if counter[x] == 1]
print(lst) # 输出 [1, 2, 5]
drop_duplicates()
函数去除重复值。import pandas as pd
lst = [1, 2, 3, 3, 4, 4, 5]
df = pd.DataFrame(lst, columns=['value'])
df = df.drop_duplicates()
lst = df['value'].tolist()
print(lst) # 输出 [1, 2, 3, 4, 5]
以上是一些常见的方法,可以根据实际情况选择合适的方法。