šŸ¾ Xarray is now 10 years old! šŸŽ‰

xarray.Dataset.from_dataframe

xarray.Dataset.from_dataframe#

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). 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.