You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
withopen(r'a.xlsx','rb') asf: # input the .xlsxdf_top=pd.read_excel(f,'Sheet1',encoding='utf-8').iloc[:,0:2]
df_less=pd.read_excel(f,'Sheet2',encoding='utf-8').iloc[:,0:2]
Problem description
The first read_excel() works fine. But the second read_excel() get the following:
Traceback (most recent call last):
File "xxx.py", line 127, in
df_less = pd.read_excel(f,'Sheet2',encoding = 'utf-8').iloc[:,0:2]
File "xxx\pandas\io\excel_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "xxx\pandas\io\excel_base.py", line 821, in init
self._reader = self._enginesengine
File "xxx\pandas\io\excel_xlrd.py", line 21, in init
super().init(filepath_or_buffer)
File "xxx\pandas\io\excel_base.py", line 350, in init
filepath_or_buffer.seek(0)
ValueError: seek of closed file
It seems the read_excel() change the io object "f". Is that some new feature in 1.0? Older versions don't have the problem.
I think it should be fixed because a function should not change the outer variable.
Expected Output
read_excel() should not change the io stream and should be able to read the same io stream several times.
Code Sample, a copy-pastable example if possible
Problem description
The first read_excel() works fine. But the second read_excel() get the following:
Traceback (most recent call last):
File "xxx.py", line 127, in
df_less = pd.read_excel(f,'Sheet2',encoding = 'utf-8').iloc[:,0:2]
File "xxx\pandas\io\excel_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "xxx\pandas\io\excel_base.py", line 821, in init
self._reader = self._enginesengine
File "xxx\pandas\io\excel_xlrd.py", line 21, in init
super().init(filepath_or_buffer)
File "xxx\pandas\io\excel_base.py", line 350, in init
filepath_or_buffer.seek(0)
ValueError: seek of closed file
It seems the read_excel() change the io object "f". Is that some new feature in 1.0? Older versions don't have the problem.
I think it should be fixed because a function should not change the outer variable.
Expected Output
read_excel() should not change the io stream and should be able to read the same io stream several times.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.0.0
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0.post20200127
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.2
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.3.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: