简体   繁体   English

熊猫read_excel

[英]Pandas read_excel

I struggled for a few hours how to read an excel file with pd.read_excel where the path is a website address.我挣扎了几个小时如何使用 pd.read_excel 读取 excel 文件,其中路径是网站地址。 I figured out that the link doesn't go directly to the file but just triggers downloading.我发现该链接不会直接转到文件,而只会触发下载。 Is there any easy way to solve it?有什么简单的方法可以解决吗?

Part of code:部分代码:

link_energy = 'http://unstats.un.org/unsd/environment/excel_file_tables/2013/Energy%20Indicators.xls'
df_energy = pd.read_excel(link_energy)

Error message:错误信息:

XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\n\n\n<!DOC'

Probably it's not a problem of pandas but my lack of skills how do do it.可能这不是熊猫的问题,但我缺乏技能怎么办。

For me works everything as expected in the following code:对我来说,在以下代码中按预期工作:

import pandas as pd
link_energy = 'http://unstats.un.org/unsd/environment/excel_file_tables/2013/Energy%20Indicators.xls'
df_energy = pd.read_excel(link_energy)
df_energy

without errors on the following env:在以下环境中没有错误:

The version of the notebook server is: 5.2.2 The server is running on this version of Python:笔记本服务器的版本是:5.2.2 服务器运行在这个版本的Python上:

Python 3.6.3 | Python 3.6.3 | packaged by conda-forge |由 conda-forge 打包 | (default, Nov 4 2017, 10:10:56) [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] (默认,2017 年 11 月 4 日,10:10:56)[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]

Current Kernel Information:当前内核信息:

Python 3.6.3 | Python 3.6.3 | packaged by conda-forge |由 conda-forge 打包 | (default, Nov 4 2017, 10:10:56) Type 'copyright', 'credits' or 'license' for more information IPython 6.2.1 -- An enhanced Interactive Python. (默认,2017 年 11 月 4 日,10:10:56)输入“版权”、“信用”或“许可证”以获取更多信息 IPython 6.2.1——增强的交互式 Python。 Type '?'类型 '?' for help.求助。

However I am not having access to your url posted.但是我无法访问您发布的网址。

but pd.read_excel won't work and you need to use pd.read_csv但是pd.read_excel不起作用,您需要使用pd.read_csv

import pandas as pd

df = pd.read_csv('https://cib.societegenerale.com/fileadmin/indices_feeds/CTA_Historical.xls')

Now you need to see the excel file what it contains what is the separator used, if there are any other values in any columns then it needs to be skipped in order to load and read useful data.现在您需要查看 excel 文件,其中包含使用的分隔符,如果任何列中有任何其他值,则需要跳过它以加载和读取有用的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM