Skip to content
Open
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
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ def value_counts_internal(
result = Series(counts, index=idx, name=name, copy=False)

if sort:
result = result.sort_values(ascending=ascending)
result = result.sort_values(ascending=ascending, kind="stable")

if normalize:
result = result / counts.sum()
Expand Down
7 changes: 6 additions & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,12 @@ def value_counts(
If True then the object returned will contain the relative
frequencies of the unique values.
sort : bool, default True
Sort by frequencies when True. Preserve the order of the data when False.
Stable sort by frequencies when True. Preserve the order of the data
when False.

.. versionchanged:: 3.0.0

Prior to 3.0.0, the sort was unstable.
ascending : bool, default False
Sort in ascending order.
bins : int, optional
Expand Down
9 changes: 7 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7718,11 +7718,16 @@ def value_counts(
normalize : bool, default False
Return proportions rather than frequencies.
sort : bool, default True
Sort by frequencies when True. Preserve the order of the data when False.
Stable sort by frequencies when True. Preserve the order of the data
when False.

.. versionchanged:: 3.0.0

Prior to 3.0.0, ``sort=False`` would sort by the columns values.

.. versionchanged:: 3.0.0

Prior to 3.0.0, the sort was unstable.
ascending : bool, default False
Sort in ascending order.
dropna : bool, default True
Expand Down Expand Up @@ -7832,7 +7837,7 @@ def value_counts(
counts.name = name

if sort:
counts = counts.sort_values(ascending=ascending)
counts = counts.sort_values(ascending=ascending, kind="stable")
if normalize:
counts /= counts.sum()

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2776,8 +2776,8 @@ def value_counts(
normalize : bool, default False
Return proportions rather than frequencies.
sort : bool, default True
Sort by frequencies when True. When False, non-grouping columns will appear
in the order they occur in within groups.
Stable sort by frequencies when True. When False, non-grouping
columns will appear in the order they occur in within groups.

.. versionchanged:: 3.0.0

Expand Down
Loading