响应内容流中的Pandas 0.25.0和xlsx [英] Pandas 0.25.0 and xlsx from response content stream

查看:67
本文介绍了响应内容流中的Pandas 0.25.0和xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

r = requests.get(projectsExportURL, auth=(username, password), verify=False,stream=True)
r.raw.decode_content = True

#add snapshot date column
df = pd.read_excel(r.raw,sheet_name='Tasks',Headers=0)

直到0.25.0和xlrd 1.2.0都可以正常工作

This worked just fine until 0.25.0 and xlrd 1.2.0

我最近不得不重做整个环境,并选择进行更新.上面的代码现在导致以下错误:

I recently had to re-do my entire environment and opted to update. The above code is now resulting in the following error:

  File "d:\python\python37\lib\site-packages\pandas\io\excel\_base.py", line 356, in __init__
    filepath_or_buffer.seek(0)

UnsupportedOperation: seek

如果我从等式中删除xlrd,pandas会抛出一个有关缺少可选库的错误(例如,如果它是可选的,那么您为什么要抱怨).

if I remove xlrd from the equation pandas throws an error about an optional library missing (like if it is optional, why are you complaining).

所以传入的数据是xlsx文件格式,我必须在文件中添加快照日期,然后将其发送到MySQL数据库.

So the incoming data is xlsx file format and I have to add a snapshot date to the file and then I send it to a MySQL database.

我该如何解决我的代码以读取对熊猫文件所做的更改的excel文件,我似乎在文档中找不到任何专门针对此问题的内容.

How can I fix my code to read the excel file with the changes to pandas, I can't seem to find anything in the docs that are specifically jumping out at me about this.

推荐答案

这是我当前有效的替换代码:

Here is my current replacement code that seems to be working:

wb = load_workbook(filename=BytesIO(r.raw.read()))
ws = wb['Tasks']
data = ws.values 
columns = next(data)[0:]

df = pd.DataFrame(data, columns=columns)

这篇关于响应内容流中的Pandas 0.25.0和xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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