Skip to content

value_counts does not respect ordered categoricals #27670

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
jpeacock29 opened this issue Jul 31, 2019 · 1 comment
Closed

value_counts does not respect ordered categoricals #27670

jpeacock29 opened this issue Jul 31, 2019 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@jpeacock29
Copy link
Contributor

Code Sample, a copy-pastable example if possible

import pandas as pd

cat = pd.Series(pd.Categorical(
                ['a', 'c', 'a', 'b', 'a'],
                categories=['a', 'b', 'c'],
                ordered=True))

cat.value_counts()

Problem description

This outputs the value counts in the order 'a', 'c', 'b' when the categorical is ordered 'a', 'b', 'c'. value_counts should respect ordered categoricals and display them appropriately.

Expected Output

value_counts outputs in the specified order: 'a', 'b', 'c'

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Darwin
OS-release : 18.6.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.0
numpy : 1.17.0
pytz : 2019.1
dateutil : 2.7.5
pip : 19.2.1
setuptools : 41.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.3.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10
IPython : 7.2.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.3.0
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@WillAyd
Copy link
Member

WillAyd commented Jul 31, 2019

Thanks but this is at its core a duplicate of #12679 . Closing for now to keep discussion and tracking material in original issue

@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Jul 31, 2019
@WillAyd WillAyd closed this as completed Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants