gpt4 book ai didi

python - 如何获取 pandas xlsxwriter 对象的二进制内容以进行 Dropbox 上传

转载 作者:行者123 更新时间:2023-11-30 22:33:19 25 4
gpt4 key购买 nike

我正在尝试将包含多个选项卡的 Excel 工作表上传到保管箱 pandasxlsxwriter 。文件不是很大,只有 5MB 左右。我正在使用 dropbox Python 3 模块

我正在做:

filename = pd.ExcelWriter('myfile.xlsx' ,engine='xlsxwriter')
actions.to_excel(filename, sheet_name="Combined Actions")
filename.save()

with open(filename, "rb") as f:
dbx.files_upload(f.read(), "/MyAPP/"+filename)

我在文档中读到files_upload需要一个字节对象。我收到错误:Type Error: Invalid file: <pandas.io.excel__XlsxWriter object at 0x000000000071C48>

此错误是因为我没有提供所需格式的文件吗?我该如何上传才能避免出现类型错误?

最佳答案

您正在尝试使用内置函数open来打开一个对象。它需要一个字符串作为其第一个参数(表示文件路径)。有关 open 功能的更多信息可以在 docs 中找到。 。

source for pandas ExcelWriter 显示它将您传递给它的文件名存储在 .path 中。因此,重命名变量以更好地表示它们的含义,并使用 ExcelWriter 实例的 .path 属性:

excel_file = pd.ExcelWriter('myfile.xlsx', engine='xlsxwriter')
actions.to_excel(excel_file, sheet_name="Combined Actions")
excel_file.save()

with open(excel_file.path, 'rb') as f:
dbx.files_upload(f.read(), '/MyAPP/'+excel_file.path)

关于python - 如何获取 pandas xlsxwriter 对象的二进制内容以进行 Dropbox 上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45185464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com