I can download the .ashx link into .xls and open it manually in Excel:
import urllib
urllib.request.urlretrieve(
'https://www.imf.org/-/media/Files/Publications/WEO/WEO-Database/2022/WEOApr2022all.ashx',
'weo.xls'
)
But when I try reading it with pandas:
import pandas as pd
pd.read_excel('weo.xls')
it gives error:
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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.