【发布时间】:2016-10-14 01:31:43
【问题描述】:
我更新了我的问题以提供更清晰的示例。
是否可以在 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(subset=['ID']) -
恐怕还没有解决问题。仍然看到同样的错误
-
df_two = df_one.drop_duplicates()也有效吗? -
很遗憾没有,得到同样的错误
-
您必须发布原始数据和重现此错误的代码,因为这似乎不是问题