polars.read_ods#
- polars.read_ods(
- source: FileSource,
- *,
- sheet_id: int | Sequence[int] | None = None,
- sheet_name: str | list[str] | tuple[str] | None = None,
- has_header: bool = True,
- columns: Sequence[int] | Sequence[str] | None = None,
- schema_overrides: SchemaDict | None = None,
- infer_schema_length: int | None = 100,
- include_file_paths: str | None = None,
- drop_empty_rows: bool = True,
- drop_empty_cols: bool = True,
- raise_if_empty: bool = True,
Read OpenOffice (ODS) spreadsheet data into a DataFrame.
- Parameters:
- source
Path to a file or a file-like object (by “file-like object” we refer to objects that have a
read()method, such as a file handler like the builtinopenfunction, or aBytesIOinstance). For file-like objects, the stream position may not be updated accordingly after reading.- sheet_id
Sheet number(s) to convert, starting from 1 (set
0to load all worksheets as DataFrames) and return a{sheetname:frame,}dict. (Defaults to1if neither this norsheet_nameare specified). Can also take a sequence of sheet numbers.- sheet_name
Sheet name(s) to convert; cannot be used in conjunction with
sheet_id. If more than one is given then a{sheetname:frame,}dict is returned.- has_header
Indicate if the first row of the table data is a header or not. If False, column names will be autogenerated in the following format:
column_x, withxbeing an enumeration over every column in the dataset, starting at 1.- columns
Columns to read from the sheet; if not specified, all columns are read. Can be given as a sequence of column names or indices.
- schema_overrides
Support type specification or override of one or more columns.
- infer_schema_length
The maximum number of rows to scan for schema inference. If set to
None, the entire dataset is scanned to determine the dtypes, which can slow parsing for large workbooks.- include_file_paths
Include the path of the source file(s) as a column with this name.
- drop_empty_rows
Indicate whether to omit empty rows when reading data into the DataFrame.
- drop_empty_cols
Indicate whether to omit empty columns (with no headers) when reading data into the DataFrame (note that empty column identification may vary depending on the underlying engine being used).
- raise_if_empty
When there is no data in the sheet,`NoDataError` is raised. If this parameter is set to False, an empty DataFrame (with no columns) is returned instead.
- Returns:
- DataFrame, or a
{sheetname: DataFrame, ...}dict if reading multiple sheets.
- DataFrame, or a
See also
Examples
Read the “data” worksheet from an OpenOffice spreadsheet file into a DataFrame.
>>> pl.read_ods( ... source="test.ods", ... sheet_name="data", ... )
If the correct dtypes can’t be determined, use the
schema_overridesparameter to specify them, or increase the inference length withinfer_schema_length.>>> pl.read_ods( ... source="test.ods", ... sheet_id=3, ... schema_overrides={"dt": pl.Date}, ... raise_if_empty=False, ... )