pandas 将工作簿内所有工作表保存到字典中
  X5zJxoD00Cah 2023年11月24日 13 0

在Pandas中,你可以使用read_excel函数的sheet_name=None参数来将一个Excel工作簿中的所有工作表读取到一个字典中³。以下是一个示例代码:

import pandas as pd

# 读取Excel文件中的所有工作表
xls = pd.read_excel('你的文件名.xlsx', sheet_name=None)

# 打印所有工作表的名称和对应的DataFrame
for sheet_name, df in xls.items():
    print(sheet_name)
    print(df)

在这个示例中,read_excel函数的sheet_name=None参数会返回一个字典,其中键是工作表的名称,值是对应的DataFrame³。然后,你可以遍历这个字典并打印每个工作表的名称和对应的DataFrame³。(1) How to convert a worksheet to a Data frame in Pandas?. https://stackoverflow.com/questions/45310787/how-to-convert-a-worksheet-to-a-data-frame-in-pandas.

(2) Write dictionary of dataframes to separate excel sheets. https://stackoverflow.com/questions/57209564/write-dictionary-of-dataframes-to-separate-excel-sheets.

(3) Save list of DataFrames to multisheet Excel spreadsheet. https://stackoverflow.com/questions/14225676/save-list-of-dataframes-to-multisheet-excel-spreadsheet.

(4) How to Convert Pandas DataFrame to a Dictionary - Data to Fish. https://datatofish.com/pandas-dataframe-to-dictionary/.

(5) Creating dictionary from excel workbook in python using sheet names as .... https://stackoverflow.com/questions/44764159/creating-dictionary-from-excel-workbook-in-python-using-sheet-names-as-key.

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月24日 0

暂无评论

推荐阅读
  X5zJxoD00Cah   2023年12月11日   14   0   0 知乎Python迭代器
  X5zJxoD00Cah   2023年12月12日   17   0   0 Python.net
X5zJxoD00Cah