Skip to content

Getting RuntimeError: dictionary changed size during iteration with read_excel #21834

@mbkupfer

Description

@mbkupfer

Code Sample, a copy-pastable example if possible

df = pd.read_excel(file)

  66 def augment_keys(adict, uri):
     67     # uri must already be enclosed in {}
---> 68     for x in adict.keys():
     69         adict[uri + x] = adict[x]
     70 

RuntimeError: dictionary changed size during iteration

Problem description

I've been getting this issue when trying to read excel files into dataframes. My workaround for now is to export as a csv and read_csv() which works fine. The read_excel method used to work before and would be nice to have it working again to avoid this extra step.

I also get this same issue w/xlrd when I run the below code, so not certain if this is a pandas issue or xlrd issue:

import xlrd
book = xlrd.open_workbook(file)

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.4.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.3
pytest: None
pip: 10.0.1
setuptools: 38.5.1
Cython: None
numpy: 1.14.0
scipy: None
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: 0.9.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO Excelread_excel, to_excel

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions