Skip to content

DOC: describe any expected ordering of value counts when sort=False #51420

Closed
@mvashishtha

Description

@mvashishtha

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

Documentation problem

The documentation says nothing about what value_counts() for series or dataframe do to order when sort=False. If there's no guarantee about the order, then the docs should say that. What I've observed is that dataframe value_counts sorts by values when sort=False, while dataframe value_counts sorts by the order that the keys first appeared in the data. For example:

import pandas as pd

df = pd.DataFrame(['b', 'a', 'a'])
# dataframe sorts by values, so index is [a, b]
print(df.value_counts(sort=False))
# dataframe sorts by order of row where each value first appears, so index is [b, a]
print(df[0].value_counts(sort=False))

Suggested fix for documentation

Explain what order to expect, if any, when sort=False.

Metadata

Metadata

Assignees

Labels

AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffDocs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions