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 – The Dataframe or Series to convert.
data_columns (default:
None) – Select which columns to assign as data. The rest are returned as coordinates. IfNone, all columns are assigned as data. Use an empty list to assign all columns as coordinates.include_trivial_index (default:
False) –from_pandascan include the index of the data frame / series as a coordinate. But when the index isRangeIndex(start=0, stop=n, step=1), wherenis the length of the data frame / series, the index is excluded by default. Set this argument toTrueto include to index anyway in this case.header_parser (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:
"bracket": Seescipp.compat.pandas_compat.parse_bracket_header(). Parses strings where the unit is given between square brackets, i.e., strings likename [unit].
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:
The converted scipp object.