如何使用极坐标获取Excel文件中的所有工作表名称

问题描述 投票:0回答:1

我们知道如何使用 Polar 读取 Excel 文件。

Import polars as pl
df = pl.read_excel()

在 pandas 中,我们有能力获取所有工作表名称。我们在 Polars 中有这样的功能吗?

xl = pd.ExcelFile('file.xlsx')

# Get sheet names
sheet_names = xl.sheet_names
python-3.x pandas dataframe python-polars
1个回答
0
投票

您可以在

PlExcelFile
的帮助下制作自己的
_initialise_spreadsheet_parser

from polars.io.spreadsheet.functions import _initialise_spreadsheet_parser

class PlExcelFile:
    def __init__(self, source, engine="xlsx2csv", engine_options={}):
        self.source = source
        self.engine = engine
        self.engine_options = engine_options

    @property
    def sheet_names(self):
        detail_sheets = _initialise_spreadsheet_parser(
            engine=self.engine, 
            source=self.file_path, 
            engine_options=self.engine_options
        )[-1]
        return [d["name"] for d in detail_sheets]

pl_xl = PlExcelFile("file.xlsx")
# pl_xl.sheet_names # Sheet1, Sheet2, ...
© www.soinside.com 2019 - 2024. All rights reserved.