Skip to content

to_excel() TyperError: Unsupported type <class 'pandas._libs.tslibs.period.Period'> in write() #26999

@riptusk331

Description

@riptusk331
Contributor

Code Sample, a copy-pastable example if possible

writer = pd.ExcelWriter(Path().resolve() / 'output' / 'out.xlsx')
for dftup in exportlist:
    dftup[0].to_excel(writer, sheet_name=dftup[2])

Problem description

Note that a similar issue was covered in in #19242, but with a different data type.
The above code takes a list of tuples which contain the DataFrames (in position 0) and the desired sheet names (in position 2) I would like to write. These DataFrames have MultiIndex columns whose levels are type PeriodIndex. The first level is an index of yearly Periods (freq='Y') and the second level an index of Quarterly periods (freq='Q').

When I try to write the DataFrames to excel, I get the following error (I can post the whole trace if needed). Any ideas?

TypeError: Unsupported type <class 'pandas._libs.tslibs.period.Period'> in write()

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.3.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.24.2
pytest: 4.5.0
pip: 19.1.1
setuptools: 41.0.1
Cython: 0.29.8
numpy: 1.16.4
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.5.0
sphinx: 2.0.1
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: 1.2.1
tables: 3.5.1
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.8
lxml.etree: 4.3.3
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.3
pymysql: None
psycopg2: 2.7.6.1 (dt dec pq3 ext lo64)
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Activity

WillAyd

WillAyd commented on Jun 22, 2019

@WillAyd
Member

If you take a look at #19244 could probably extend that to make sure this is supported. Want to try a PR?

added this to the Contributions Welcome milestone on Jun 22, 2019
riptusk331

riptusk331 commented on Jun 22, 2019

@riptusk331
ContributorAuthor

Sure thing - I'll have a look and create a PR.

riptusk331

riptusk331 commented on Jun 23, 2019

@riptusk331
ContributorAuthor

Ok so I have identified the source of the bug - but I have a question before I do a PR. It looks like the Excel IO has been changed a bit on the master branch from what the current stable 0.24.2 release is. I know where to make the change in both versions, but am not sure which I should push.

Thanks

jreback

jreback commented on Jun 23, 2019

@jreback
Contributor

only PR to master

modified the milestones: Contributions Welcome, 0.25.0 on Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO Excelread_excel, to_excelPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @WillAyd@jreback@riptusk331

      Issue actions

        to_excel() TyperError: Unsupported type <class 'pandas._libs.tslibs.period.Period'> in write() · Issue #26999 · pandas-dev/pandas