-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Inconsistent treatment of categories in multi-level unstack #15239
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
Comments
@Kevin-McIsaac Thanks for the report, that sounds like a bug. From a quick look, the categorical is lost in the |
@Kevin-McIsaac BTW, another way to do this instead of using the sequential unstacking/stacking is to reindex with the desired index (which you can construct with
|
this is a dupe of #14018 |
A smaller reproducible example: Stacking one categorical level keeps the categorical intact:
Stacking two categorical levels: the second becomes a plain index:
|
@jorisvandenbossche its the |
@jreback the other issue is about the values, here it is index itself, see my example in the comment above |
@jorisvandenbossche thanks for sharing a much simpler way to get the same result. I learnt something useful. |
This looks to be correct on master now. Could use a test
|
Code Sample, a copy-pastable example if possible
Problem description
Hours and Station are categories. After the stack/unstack Hours remains a category but Station becomes an object.
If I switch the order of the Station and Hours in unstack the Station remains categorical and Hours becomes an object.
Expected Output
Hours and Station both remain categorical (prefered) or both become the underlying type of.
Output of
pd.show_versions()
pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.11.3
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.1.4
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.9.4
boto: 2.45.0
pandas_datareader: None
The text was updated successfully, but these errors were encountered: