pd.read_excel ValueError: File is not a recognized excel file
pd.read_excel ValueError: File is not a recognized excel file
我可以将 .ashx link 下载到 .xls 中并在 Excel 中手动打开它:
import urllib
urllib.request.urlretrieve(
'https://www.imf.org/-/media/Files/Publications/WEO/WEO-Database/2022/WEOApr2022all.ashx',
'weo.xls'
)
但是当我尝试用 pandas 阅读它时:
import pandas as pd
pd.read_excel('weo.xls')
它给出错误:
Traceback (most recent call last):
File "", line 1, in
pd.read_excel('weo.xls')
File "C:\Anaconda3\lib\site-packages\pandas\util_decorators.py",
line 299, in wrapper
return func(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\pandas\io\excel_base.py", line
336, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "C:\Anaconda3\lib\site-packages\pandas\io\excel_base.py", line
1071, in init
ext = inspect_excel_format(
File "C:\Anaconda3\lib\site-packages\pandas\io\excel_base.py", line
965, in inspect_excel_format
raise ValueError("File is not a recognized excel file")
ValueError: File is not a recognized excel file
这是一个由制表符分隔的 csv 文件,并不完全是一种直接的数据帧格式:
pd.read_csv('weo.csv', sep='\t', encoding='utf_16_le')
我可以将 .ashx link 下载到 .xls 中并在 Excel 中手动打开它:
import urllib
urllib.request.urlretrieve(
'https://www.imf.org/-/media/Files/Publications/WEO/WEO-Database/2022/WEOApr2022all.ashx',
'weo.xls'
)
但是当我尝试用 pandas 阅读它时:
import pandas as pd
pd.read_excel('weo.xls')
它给出错误:
Traceback (most recent call last):
File "", line 1, in pd.read_excel('weo.xls')
File "C:\Anaconda3\lib\site-packages\pandas\util_decorators.py", line 299, in wrapper return func(*args, **kwargs)
File "C:\Anaconda3\lib\site-packages\pandas\io\excel_base.py", line 336, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "C:\Anaconda3\lib\site-packages\pandas\io\excel_base.py", line 1071, in init ext = inspect_excel_format(
File "C:\Anaconda3\lib\site-packages\pandas\io\excel_base.py", line 965, in inspect_excel_format raise ValueError("File is not a recognized excel file")
ValueError: File is not a recognized excel file
这是一个由制表符分隔的 csv 文件,并不完全是一种直接的数据帧格式:
pd.read_csv('weo.csv', sep='\t', encoding='utf_16_le')