pandas read_excel [英] Pandas read_excel

查看:47
本文介绍了 pandas read_excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎了几个小时如何使用 pd.read_excel 读取 excel 文件,其中路径是网站地址.我发现该链接不会直接转到文件,而只会触发下载.有什么简单的方法可以解决吗?

I struggled for a few hours how to read an excel file with pd.read_excel where the path is a website address. 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?

部分代码:

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

错误信息:

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:

笔记本服务器版本为:5.2.2服务器在此版本的 Python 上运行:

The version of the notebook server is: 5.2.2 The server is running on this version of Python:

Python 3.6.3 |由 conda-forge 打包 |(默认,2017 年 11 月 4 日,10:10:56)[GCC 4.8.2 20140120 (红帽 4.8.2-15)]

Python 3.6.3 | packaged by conda-forge | (default, Nov 4 2017, 10:10:56) [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]

当前内核信息:

Python 3.6.3 |由 conda-forge 打包 |(默认,2017 年 11 月 4 日,10:10:56)输入版权"、信用"或许可"以获取更多信息IPython 6.2.1——增强的交互式 Python.类型 '?'寻求帮助.

Python 3.6.3 | packaged by 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. Type '?' for help.

这篇关于 pandas read_excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆