Pandas xlrd 引擎传递的静态值错误
Pandas xlrd engine passed still value error
我正在尝试从 url:
中读取一个 xls 文件
使用请求:
page = requests.get(url) # xls url
df = pd.read_excel(page.content,engine = 'xlrd') #engine is passed
File "f:\python36\lib\site-packages\pandas\util\_decorators.py", line 118, in wrapper
return func(*args, **kwargs)
File "f:\python36\lib\site-packages\pandas\io\excel.py", line 230, in read_excel
io = ExcelFile(io, engine=engine)
File "f:\python36\lib\site-packages\pandas\io\excel.py", line 296, in __init__
raise ValueError('Must explicitly set engine if not passing in'
ValueError: Must explicitly set engine if not passing in buffer or path for io.
# if i put in random engine name it throws an unsupported engine error but with xlrd it throws must set engine
我尝试保存文件然后读取它:
with open('file.xls','wb') as f:
f.write(page.content)
df = pd.read_excel('file.xls',engine='xlrd') #this works
编辑:
我试过通过 page.text 它提出:
ValueError: embedded null character
如果 pd.read_excel
的第一个参数是 str
,它被解释为文件的 路径(或 URL ).如果我们希望将文件的内容直接传递给
read_excel
,那么我们需要将内容包裹在一个BytesIO
中,使其成为
类文件对象:
因此,使用
BytesIO = pd.io.common.BytesIO
df = pd.read_excel(BytesIO(page.content), engine='xlrd')
我正在尝试从 url:
中读取一个 xls 文件使用请求:
page = requests.get(url) # xls url
df = pd.read_excel(page.content,engine = 'xlrd') #engine is passed
File "f:\python36\lib\site-packages\pandas\util\_decorators.py", line 118, in wrapper
return func(*args, **kwargs)
File "f:\python36\lib\site-packages\pandas\io\excel.py", line 230, in read_excel
io = ExcelFile(io, engine=engine)
File "f:\python36\lib\site-packages\pandas\io\excel.py", line 296, in __init__
raise ValueError('Must explicitly set engine if not passing in'
ValueError: Must explicitly set engine if not passing in buffer or path for io.
# if i put in random engine name it throws an unsupported engine error but with xlrd it throws must set engine
我尝试保存文件然后读取它:
with open('file.xls','wb') as f:
f.write(page.content)
df = pd.read_excel('file.xls',engine='xlrd') #this works
编辑:
我试过通过 page.text 它提出:
ValueError: embedded null character
如果 pd.read_excel
的第一个参数是 str
,它被解释为文件的 路径(或 URL ).如果我们希望将文件的内容直接传递给
read_excel
,那么我们需要将内容包裹在一个BytesIO
中,使其成为
类文件对象:
因此,使用
BytesIO = pd.io.common.BytesIO
df = pd.read_excel(BytesIO(page.content), engine='xlrd')