# xarray.Dataset.from_dataframe

#### *classmethod* Dataset.from_dataframe(dataframe, sparse=False)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L7587-L7671)

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 use
xr.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`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html#pandas.DataFrame)) – DataFrame from which to copy data and indices.
  * **sparse** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#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.`

#### SEE ALSO
[`xarray.DataArray.from_series`](xarray.DataArray.from_series.html.md#xarray.DataArray.from_series), [`pandas.DataFrame.to_xarray`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_xarray.html#pandas.DataFrame.to_xarray)
