我需要从链接导入excel文件。我试着用它来做
filedlurl = 'https://www.nordpoolgroup.com/48d3ac/globalassets/marketdata-excel-files/exchange-ee-connections_2021_daily.xls'
df = pd.read_excel(filedlurl, skiprows=2)
但是错误是XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'Exchange'
然后我找到了下面的方法 using Pandas to read in excel file from URL - XLRDError
df = pd.read_csv('https://www.nordpoolgroup.com/48d3ac/globalassets/marketdata-excel-files/exchange-ee-connections_2021_daily.xls',
#sep='\t',
#parse_dates=[0],
names=['a','b','c','d','e','f'],
skiprows=2)
df
这里还有一个奇怪的输出。 从web手动下载时,如何获取下表
最新的pandas(pandas==1.2.0)能够在安装
requests
时使用pd.read_excel
从url读取但您的文件似乎已损坏,它会触发:
您的文件不是CSV或Excel文件。实际内容是一个HTML表(如下所示)
像这样使用
pd.read_html
:您可以在Excel中打开文件是因为Excel会迭代可能的格式,直到找到有效的格式。例如,你可以制作一个标签分隔的值(应该有扩展名.tsv)文件,append.xls,虽然它不是一个真正可怕的电子表格格式(xls),Excel仍然会正常打开它。它还可以对HTML数据执行此操作
首先,可以通过以下方式使用Python下载文件:urllib.request
然后在使用熊猫中阅读:
这将给你:
在使用真正的Excel进行检查后,我发现:
我怀疑你的档案有问题。对于正确的文件,上述方法应该有效
相关问题 更多 >
编程相关推荐