Skip to content

pd.concat reordering categorical levels lexically #7864

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
has2k1 opened this issue Jul 29, 2014 · 0 comments · Fixed by #7850
Closed

pd.concat reordering categorical levels lexically #7864

has2k1 opened this issue Jul 29, 2014 · 0 comments · Fixed by #7850
Labels
Bug Categorical Categorical Data Type
Milestone

Comments

@has2k1
Copy link
Contributor

has2k1 commented Jul 29, 2014

Look at dfx

In [1]: import pandas as pd

In [2]: df = pd.DataFrame({"id":[1,2,3,4,5,6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
   ...: df["grade"] = pd.Categorical(df["raw_grade"])
   ...: df['grade'].cat.reorder_levels(['e', 'a', 'b'])
   ...: 

In [3]: df1 = df[0:3]
   ...: df2 = df[3:]
   ...: 

In [4]: df['grade'].cat.levels
Out[4]: Index([u'e', u'a', u'b'], dtype='object')

In [5]: df1['grade'].cat.levels
Out[5]: Index([u'e', u'a', u'b'], dtype='object')

In [6]: df2['grade'].cat.levels
Out[6]: Index([u'e', u'a', u'b'], dtype='object')

In [7]: dfx = pd.concat([df1, df2])

In [8]: dfx['grade'].cat.levels
Out[8]: Index([u'a', u'b', u'e'], dtype='object')

version: pandas: 0.14.1-78-g24b309f

This is still the case after either of PR #7768 and PR #7850.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants