You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
importpandasaspddf=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.
The text was updated successfully, but these errors were encountered:
phofl
added
Algos
Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff
and removed
Needs Triage
Issue that has not been reviewed by a pandas team member
labels
Feb 23, 2023
@phofl I have made the changes but it's failing one of the tests (Ubuntu / Numpy Dev Test(not single_cpu)). This is my first contribution and I would really appreciate any help.
Pandas version checks
main
hereLocation of the documentation
Documentation problem
The documentation says nothing about what
value_counts()
for series or dataframe do to order whensort=False
. If there's no guarantee about the order, then the docs should say that. What I've observed is that dataframevalue_counts
sorts by values whensort=False
, while dataframe value_counts sorts by the order that the keys first appeared in the data. For example:Suggested fix for documentation
Explain what order to expect, if any, when
sort=False
.The text was updated successfully, but these errors were encountered: