Using a CategoricalIndex
with interval categories as column index breaks operations on a DataFrame
#27415
Labels
Milestone
Code Sample, a copy-pastable example if possible
Problem description
When the columns index is a
CategoricalIndex
with interval categories, basic operations like multiplication by a scalar are broken.The minimal example is a contrived case, but the situation can arise in common data analysis workflows:
pd.cut
to bin floating point valuespivot_table
operation with the binned values as columnsFor instance:
A DataFrame with a column index of this kind is brokwn in other ways, for example it does not display as an HTML table in a Jupyter notebook, etc.
Expected Output
Workaround
df.columns = df.columns.categories
seems to make the DataFrame behave correctly.Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.123-86.109.amzn1.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.24.2
pytest: 3.5.1
pip: 10.0.1
setuptools: 39.1.0
Cython: 0.28.4
numpy: 1.15.4
scipy: 1.1.0
pyarrow: 0.14.0
xarray: None
IPython: 6.4.0
sphinx: 1.7.4
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: None
matplotlib: 3.0.3
openpyxl: 2.5.3
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.4
lxml.etree: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.11
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: 0.1.5
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: