Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如何从请求响应中读取excel文件?_Python_Pandas_Python Requests_Xlrd - Fatal编程技术网

Python:如何从请求响应中读取excel文件?

Python:如何从请求响应中读取excel文件?,python,pandas,python-requests,xlrd,Python,Pandas,Python Requests,Xlrd,我正在使用请求库以流的形式下载excel文件 r=requests.get(我的url,stream=True) 我想读取这个excel文件中的数据,因为我可以尝试使用熊猫。但是我不知道如何从我得到的响应中读取文件。我能做什么 您可以直接使用pandas中的url来读取excel文件,而无需使用请求 import pandas as pd df = pd.read_excel(my_url) 如果需要通过请求检索数据,则此处的回答()可能就足够了: 只需将文件内容包装在BytesIO中: i

我正在使用请求库以流的形式下载excel文件

r=requests.get(我的url,stream=True)


我想读取这个excel文件中的数据,因为我可以尝试使用熊猫。但是我不知道如何从我得到的响应中读取文件。我能做什么

您可以直接使用pandas中的url来读取excel文件,而无需使用请求

import pandas as pd

df = pd.read_excel(my_url)
如果需要通过请求检索数据,则此处的回答()可能就足够了:

只需将文件内容包装在BytesIO中:

import pandas as pd
import io

with io.BytesIO(r.content) as fh:
    df = pd.io.excel.read_excel(fh, sheetname=0)