to_dataframe

UnitsAwareDataArray.to_dataframe(name: Hashable | None = None, dim_order: Sequence[Hashable] | None = None) DataFrame

Convert this array and its coordinates into a tidy pandas.DataFrame.

The DataFrame is indexed by the Cartesian product of index coordinates (in the form of a pandas.MultiIndex). Other coordinates are included as columns in the DataFrame.

For 1D and 2D DataArrays, see also DataArray.to_pandas() which doesn’t rely on a MultiIndex to build the DataFrame.

Parameters:
  • name (Hashable or None, optional) – Name to give to this array (required if unnamed).

  • dim_order (Sequence of Hashable or None, optional) –

    Hierarchical dimension order for the resulting dataframe. Array content is transposed to this order and then written out as flat vectors in contiguous order, so the last dimension in this list will be contiguous in the resulting DataFrame. This has a major influence on which operations are efficient on the resulting dataframe.

    If provided, must include all dimensions of this DataArray. By default, dimensions are sorted according to the DataArray dimensions order.

Returns:

result – DataArray as a pandas DataFrame.

Return type:

DataFrame

See also

DataArray.to_pandas, DataArray.to_series