从pandas ExcelWriter对象读取表单到数据帧

2024-10-02 14:17:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个pandas ExcelWriter对象,其中有几个工作表,它们是从excel电子表格加载的。我现在想读出一个数据帧。我知道我可以从原始的excel电子表格中读取它,但是我想从ExcelWriter对象中检索数据。在

正在使用openpyxl加载工作表

testwriter = pd.ExcelWriter(filename, engine = 'openpyxl')
testwriter.book = openpyxl.load_workbook(filename)
testwriter.sheets = dict((ws.title, ws) for ws in book.worksheets)
dataframe = pd.DataFrame(testwriter.sheets['sheetname']) ???

Tags: 数据对象pandaswsloadfilenameexcelengine
1条回答
网友
1楼 · 发布于 2024-10-02 14:17:07

将现有的openpyxl工作表转换为Pandas数据帧非常简单。虽然2.4版将提供最好的支持,但所有版本的原则都是一样的:循环工作表中的行并返回单元格值。

请参阅openpyxl 2.4 documentation for working with Pandas了解一些想法。

顺便说一句,不需要创建testwriter.sheets字典:使用`book['sheetname']。

相关问题 更多 >

    热门问题