xarray.Dataset.from_dataframe (original) (raw)
classmethod Dataset.from_dataframe(dataframe, sparse=False)[source]#
Convert a pandas.DataFrame into an xarray.Dataset
Each column will be converted into an independent variable in the Dataset. If the dataframe’s index is a MultiIndex, it will be expanded into a tensor product of one-dimensional indices (filling in missing values with NaN). If you rather preserve the MultiIndex usexr.Dataset(df). This method will produce a Dataset very similar to that on which the ‘to_dataframe’ method was called, except with possibly redundant dimensions (since all dataset variables will have the same dimensionality).
Parameters:
- dataframe (DataFrame) – DataFrame from which to copy data and indices.
- sparse (bool, default: False) – If true, create a sparse arrays instead of dense numpy arrays. This can potentially save a large amount of memory if the DataFrame has a MultiIndex. Requires the sparse package (sparse.pydata.org).
Returns:
New Dataset.