scipp.compat.pandas_compat.from_pandas#

scipp.compat.pandas_compat.from_pandas(pd_obj, *, data_columns=None, include_trivial_index=False, header_parser=None)#

Converts a pandas.DataFrame or pandas.Series object into a scipp Dataset or DataArray respectively.

Parameters:
  • pd_obj (DataFrame | Series) – The Dataframe or Series to convert.

  • data_columns (Union[str, Iterable[str], None], default: None) – Select which columns to assign as data. The rest are returned as coordinates. If None, all columns are assigned as data. Use an empty list to assign all columns as coordinates.

  • include_trivial_index (bool, default: False) – from_pandas can include the index of the data frame / series as a coordinate. But when the index is RangeIndex(start=0, stop=n, step=1), where n is the length of the data frame / series, the index is excluded by default. Set this argument to True to include to index anyway in this case.

  • header_parser (Union[Literal['bracket'], Callable[[str], tuple[str, Unit | None]], None], default: None) –

    Parses each column header to extract a name and unit for each data array. By default, it returns the column name and uses the default unit. Builtin parsers can be specified by name:

    Before implementing a custom parser, check out scipp.compat.pandas_compat.parse_bracket_header() to get an overview of how to handle edge cases.

Returns:

DataArray | Dataset – The converted scipp object.