Minio httpresponse |解码到DataFrame或Excel

发布于 2025-01-24 11:29:09 字数 757 浏览 2 评论 0原文

目标:在内存中创建数据框,或在本地存储文件。

努力解码Excel文件;我可以解码所有其他文件类型。

代码:

from MinioConn import MinioConn
from io import StringIO
import pandas as pd
import os

client = MinioConn().client()
obj = client.get_object('bucket-name', 'dir/file.xls')

print(type(obj))
print(obj.read())

filename = 'temp.xlsx'
new_file = open(filename, 'w')
try:
    new_file.write(obj.response)  # .content
    new_file.close()
    df = pd.read_excel(filename)
except:
    os.remove(filename)

Trackback:

<class 'urllib3.response.HTTPResponse'>
2\n\x00q\x0b\x00\x00@\x00\x00\x00,@\xfd\x00\n\x00q\x0b\x01\x00\x0f\x00\xc2\x02\x00\x00\xfd\x00\n\x ...

请告诉我是否应该添加其他内容以发布/澄清。

Goal: create either a Dataframe in memory or store file locally.

Struggling to decode Excel files; I can decode all other file types.

Code:

from MinioConn import MinioConn
from io import StringIO
import pandas as pd
import os

client = MinioConn().client()
obj = client.get_object('bucket-name', 'dir/file.xls')

print(type(obj))
print(obj.read())

filename = 'temp.xlsx'
new_file = open(filename, 'w')
try:
    new_file.write(obj.response)  # .content
    new_file.close()
    df = pd.read_excel(filename)
except:
    os.remove(filename)

Traceback:

<class 'urllib3.response.HTTPResponse'>
2\n\x00q\x0b\x00\x00@\x00\x00\x00,@\xfd\x00\n\x00q\x0b\x01\x00\x0f\x00\xc2\x02\x00\x00\xfd\x00\n\x ...

Please let me know if I should add anything else to post/ clarify.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文