Skip to content

Drop duplicates #56957

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6721,6 +6721,24 @@ def drop_duplicates(
DataFrame or None
DataFrame with duplicates removed or None if ``inplace=True``.

Notes
--------
The methods :meth:`pandas.DataFrame.drop_duplicates` and :meth:`pandas.DataFrame.duplicated` rely on hashing.
Therefore, using a column with mutable objects, such as lists (are not hashable), in the subset parameter may result in unexpected behavior.

To handle mutable objects, 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)
>>> df['item_ids'] = df['item_ids'].apply(list)
number item_ids
0 1 [1, 2, 3]

See Also
--------
DataFrame.value_counts: Count unique combinations of columns.
Expand Down
8 changes: 4 additions & 4 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def hist_series(

Returns
-------
matplotlib.AxesSubplot
matplotlib.Axes
A histogram plot.

See Also
Expand Down Expand Up @@ -227,7 +227,7 @@ def hist_frame(

Returns
-------
matplotlib.AxesSubplot or numpy.ndarray of them
matplotlib.Axes or numpy.ndarray of them

See Also
--------
Expand Down Expand Up @@ -1374,7 +1374,7 @@ def hist(

Returns
-------
class:`matplotlib.AxesSubplot`
class:`matplotlib.Axes`
Return a histogram plot.

See Also
Expand Down Expand Up @@ -1794,7 +1794,7 @@ def hexbin(

Returns
-------
matplotlib.AxesSubplot
matplotlib.Axes
The matplotlib ``Axes`` on which the hexbin is plotted.

See Also
Expand Down