-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.drop_duplicates method fails when a column with a list… #56958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6748,6 +6748,22 @@ def drop_duplicates( | |
DataFrame or None | ||
DataFrame with duplicates removed or None if ``inplace=True``. | ||
|
||
Notes | ||
------- | ||
To handle mutable objects such as list, convert the list column | ||
to a tuple before using it in the subset. | ||
|
||
>>> df = pd.DataFrame([ | ||
... {'number': 1, 'item_ids': [1, 2, 3]}, | ||
... {'number': 1, 'item_ids': [1, 2, 3]}, | ||
... ]) | ||
|
||
>>> df['item_ids'] = df['item_ids'].apply(tuple) | ||
>>> df.drop_duplicates(inplace=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
>>> df['item_ids'] = df['item_ids'].apply(list) | ||
number item_ids | ||
0 1 [1, 2, 3] | ||
Comment on lines
+6763
to
+6765
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line doesn't produce any output. If you want to show output, you can make it just |
||
|
||
See Also | ||
-------- | ||
DataFrame.value_counts: Count unique combinations of columns. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not handle all cases. I think the note should start with something more general like: