Skip to content

BUG: misplaced index_label with DF.to_excel() #6260

Closed
@iled

Description

@iled

When saving an excel file from a DataFrame with the method to_excel, there is a misbehaviour with index_label: it is placed in the 2nd row.

For instance

>>> df = pd.DataFrame([[1,2,3],[4,5,6]], columns=['a', 'b', 'c'])
>>> df.index.name = 'n'
>>> df
   a  b  c
n         
0  1  2  3
1  4  5  6

[2 rows x 3 columns]
>>> df.to_excel(path, index_label='test')

Produces the following result within the xls file:

screenshot from 2014-02-05 01 36 35

Even if I force index_label=None, the behaviour persists

>>> df.to_excel('/home/julio/Testes/cost-home/test.xls', index_label=None)

Which is written as

screenshot from 2014-02-05 01 39 10

This is a problem because then I can't read the same DF after I write it:

>>> df2 = pd.read_excel('/home/julio/Testes/cost-home/test.xls', 0)
>>> df2
    a   b   c
n NaN NaN NaN
0   1   2   3
1   4   5   6

[3 rows x 3 columns]

I'm using pandas 0.13.0. In version 0.12 the label index was inserted in the first row.

>>> show_versions()

INSTALLED VERSIONS
------------------
Python: 2.7.4.final.0
OS: Linux
Release: 3.8.0-19-generic
Processor: x86_64
byteorder: little
LC_ALL: None
LANG: pt_PT.UTF-8

pandas: 0.13.0
Cython: 0.19.1
Numpy: 1.8.0
Scipy: 0.13.2
statsmodels: 0.5.0
    patsy: 0.2.1
scikits.timeseries: Not installed
dateutil: 2.2
pytz: 2013.9
bottleneck: 0.7.0
PyTables: 3.0.0
    numexpr: 2.2.2
matplotlib: 1.3.1
openpyxl: 1.6.2
xlrd: 0.9.2
xlwt: 0.7.5
xlsxwriter: 0.5.2
sqlalchemy: Not installed
lxml: 3.2.3
bs4: Not installed
html5lib: Not installed
bigquery: Not installed
apiclient: Not installed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions