8
我已更新我的問題以提供更清晰的示例。pandas drop_duplicates - TypeError:在*之後鍵入對象參數必須是一個序列,而不是映射
是否可以使用Pandas中的drop_duplicates方法根據值包含列表的列ID刪除重複的行。考慮由列表中的兩個項目組成的列「三」。有沒有辦法刪除重複的行,而不是迭代地做(這是我目前的解決方法)。
import pandas as pd
data = [
{'one': 50, 'two': '5:00', 'three': 'february'},
{'one': 25, 'two': '6:00', 'three': ['february', 'january']},
{'one': 25, 'two': '6:00', 'three': ['february', 'january']},
{'one': 25, 'two': '6:00', 'three': ['february', 'january']},
{'one': 90, 'two': '9:00', 'three': 'january'}
]
df = pd.DataFrame(data)
print(df)
one three two
0 50 february 5:00
1 25 [february, january] 6:00
2 25 [february, january] 6:00
3 25 [february, january] 6:00
4 90 january 9:00
df.drop_duplicates(['three'])
導致以下錯誤:
TypeError: type object argument after * must be a sequence, not map
'df_two = df_one.drop_duplicates( 'ID')'或'具體= df_two df_one.drop_duplicates(子集= [ 'ID'])' – EdChum
害怕沒有解決問題。仍然看到相同的錯誤 – user3939059
'df_two = df_one.drop_duplicates()'工作嗎? – EdChum