question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting RuntimeError: dictionary changed size during iteration with `read_excel`

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
WillAydcommented, Jul 9, 2018

Your problem looks to have been addressed within xlrd:

https://github.com/python-excel/xlrd/issues/30

Should just need to upgrade from 0.9.0

0reactions
dongzhi0312commented, Jan 4, 2019

yes,thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

dictionary changed size during iteration" error? - Stack Overflow
The reason for the runtime error is that you cannot iterate through a data structure while its structure is changing during iteration.
Read more >
RuntimeError: dictionary changed size during iteration
The Python RuntimeError: dictionary changed size during iteration occurs when we change the size of a dictionary when iterating over it.
Read more >
Runtimeerror: Dictionary Changed Size During Iteration
The runtimeerror: dictionary changed size during iteration occurs whenever you modify entries in a dictionary object during iteration.
Read more >
Filtering Dictionary In Python 3. “RuntimeError - codeburst
RuntimeError : Dictionary changed size during iteration”, Python slaps you in your face when you try to add/remove entries in dict object during...
Read more >
xlrd.open_workbook 报错for x in adict.keys(): RuntimeError
xlrd.open_workbook 报错for x in adict.keys(): RuntimeError: dictionary change size during iteration. 一起学python吧 于 2019-05-27 16:48:39 发布 399 收藏.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found