df.to_excel() error.Unsupported type <type 'pandas._libs.interval.Interval'> in write() · Issue #19242 · pandas-dev/pandas (original) (raw)

With pandas version 0.19.*,code can run normally.

But in pandas0.20+,the following error will be displayed.

Code

import pandas as pd import numpy as np

print(pd.version) df = pd.DataFrame(np.random.random((20, 2))) df['new'] = pd.cut(df[0], 10) df.to_excel('test.xlsx')

Error description

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/fc/virtual/rock_env/lib/python2.7/site-packages/pandas/core/frame.py", line 1424, in to_excel
    engine=engine)
  File "/Users/fc/virtual/rock_env/lib/python2.7/site-packages/pandas/io/formats/excel.py", line 628, in write
    freeze_panes=freeze_panes)
  File "/Users/fc/virtual/rock_env/lib/python2.7/site-packages/pandas/io/excel.py", line 1600, in write_cells
    val, style)
  File "/Users/fc/virtual/rock_env/lib/python2.7/site-packages/xlsxwriter/worksheet.py", line 65, in cell_wrapper
    return method(self, *args, **kwargs)
  File "/Users/fc/virtual/rock_env/lib/python2.7/site-packages/xlsxwriter/worksheet.py", line 433, in write
    raise TypeError("Unsupported type %s in write()" % type(token))
TypeError: Unsupported type <type 'pandas._libs.interval.Interval'> in write()

Note: The same error in pandas0.21,0.20. Right in 0.19.*

Output of pd.show_versions()

commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 17.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 38.2.4
Cython: None
numpy: 1.13.3
scipy: 1.0.0
xarray: None
IPython: None
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: 1.0.2
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
pandas_gbq: None
pandas_datareader: None