Skip to content

BUG: read_excel issue - 1 #34747

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

Open
2 of 3 tasks
kuraga opened this issue Jun 13, 2020 · 1 comment
Open
2 of 3 tasks

BUG: read_excel issue - 1 #34747

kuraga opened this issue Jun 13, 2020 · 1 comment
Labels
Bug IO Excel read_excel, to_excel

Comments

@kuraga
Copy link

kuraga commented Jun 13, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

See Problem description.

Problem description

import pandas as pd
pd.read_excel('test.xlsx', header=[0, 1], index_col=0, engine='openpyxl')

produces

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    pd.read_excel('test.xlsx', header=[0, 1], index_col=0, engine='openpyxl')
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 334, in read_excel
    **kwds,
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 888, in parse
    **kwds,
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 521, in parse
    ].columns.set_names(header_names)
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 1325, in set_names
    idx._set_names(names, level=level)
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 1239, in _set_names
    raise ValueError(f"Length of new names must be 1, got {len(values)}")
ValueError: Length of new names must be 1, got 2
import pandas as pd
pd.read_excel('test.xlsx', header=[0, 1], index_col=0, engine='xlrd')

produces

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    pd.read_excel('test.xlsx', header=[0, 1], index_col=0, engine='xlrd')
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 334, in read_excel
    **kwds,
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 888, in parse
    **kwds,
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/excel/_base.py", line 512, in parse
    **kwds,
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 2201, in TextParser
    return TextFileReader(*args, **kwds)
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 880, in __init__
    self._make_engine(self.engine)
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 1126, in _make_engine
    self._engine = klass(self.f, **self.options)
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 2298, in __init__
    self.columns, self.index_names, self.col_names
  File "/home/sasha/miniconda3/lib/python3.7/site-packages/pandas/io/parsers.py", line 1495, in _extract_multi_indexer_columns
    for n in range(len(columns[0])):
IndexError: list index out of range

image
test.xlsx

Expected Output

No exceptions.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.42-calculate
machine : x86_64
processor : Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
byteorder : little
LC_ALL : None
LANG : ru_RU.utf8
LOCALE : ru_RU.UTF-8

pandas : 1.0.3
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.4.0.post20200518
Cython : 0.29.17
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.2.8
lxml.etree : 4.5.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.13.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.5.0
matplotlib : 3.1.3
numexpr : None
odfpy : None
openpyxl : 3.0.3
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : 1.2.8
numba : None

@kuraga kuraga added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 13, 2020
@alimcmaster1 alimcmaster1 added IO Excel read_excel, to_excel and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 20, 2020
@asishm
Copy link
Contributor

asishm commented Sep 12, 2020

Doesn't seem to be raising an exception in v1.1.1
but there seem to be issues

In [59]: df = pd.read_excel('Downloads/test.xlsx', header=[0,1], index_col=0)

In [60]: df
Out[60]:
A  D
B  E
C  F

In [61]: df.values
Out[61]: array([['F']], dtype=object)

In [62]: df = pd.read_excel('Downloads/test.xlsx', header=[0,1], index_col=0, engine='openpyxl')

In [63]: df
Out[63]:
A  D                                           ...
B  E E.1 E.2 E.3 E.4 E.5 E.6 E.7 E.8 E.9 E.10  ... E.1012 E.1013 E.1014 E.1015 E.1016 E.1017 E.1018 E.1019 E.1020 E.1021 E.1022
C  F NaN NaN NaN NaN NaN NaN NaN NaN NaN  NaN  ...    NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN    NaN

[1 rows x 1023 columns]

In [64]: pd.__version__
Out[64]: '1.1.1'

In [66]: df = pd.read_excel('Downloads/test.xlsx', header=[0,1], index_col=0, engine='xlrd')

In [67]: df
Out[67]:
A  D
B  E
C  F

@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Jan 19, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

5 participants