def to_xarray(self):
    "\n        Return an xarray object from the pandas object.\n\n        Returns\n        -------\n        xarray.DataArray or xarray.Dataset\n            Data in the pandas structure converted to Dataset if the object is\n            a DataFrame, or a DataArray if the object is a Series.\n\n        See Also\n        --------\n        DataFrame.to_hdf : Write DataFrame to an HDF5 file.\n        DataFrame.to_parquet : Write a DataFrame to the binary parquet format.\n\n        Notes\n        -----\n        See the `xarray docs <http://xarray.pydata.org/en/stable/>`__\n\n        Examples\n        --------\n        >>> df = pd.DataFrame([('falcon', 'bird',  389.0, 2),\n        ...                    ('parrot', 'bird', 24.0, 2),\n        ...                    ('lion',   'mammal', 80.5, 4),\n        ...                    ('monkey', 'mammal', np.nan, 4)],\n        ...                    columns=['name', 'class', 'max_speed',\n        ...                             'num_legs'])\n        >>> df\n             name   class  max_speed  num_legs\n        0  falcon    bird      389.0         2\n        1  parrot    bird       24.0         2\n        2    lion  mammal       80.5         4\n        3  monkey  mammal        NaN         4\n\n        >>> df.to_xarray()\n        <xarray.Dataset>\n        Dimensions:    (index: 4)\n        Coordinates:\n          * index      (index) int64 0 1 2 3\n        Data variables:\n            name       (index) object 'falcon' 'parrot' 'lion' 'monkey'\n            class      (index) object 'bird' 'bird' 'mammal' 'mammal'\n            max_speed  (index) float64 389.0 24.0 80.5 nan\n            num_legs   (index) int64 2 2 4 4\n\n        >>> df['max_speed'].to_xarray()\n        <xarray.DataArray 'max_speed' (index: 4)>\n        array([389. ,  24. ,  80.5,   nan])\n        Coordinates:\n          * index    (index) int64 0 1 2 3\n\n        >>> dates = pd.to_datetime(['2018-01-01', '2018-01-01',\n        ...                         '2018-01-02', '2018-01-02'])\n        >>> df_multiindex = pd.DataFrame({'date': dates,\n        ...                    'animal': ['falcon', 'parrot', 'falcon',\n        ...                               'parrot'],\n        ...                    'speed': [350, 18, 361, 15]}).set_index(['date',\n        ...                                                    'animal'])\n        >>> df_multiindex\n                           speed\n        date       animal\n        2018-01-01 falcon    350\n                   parrot     18\n        2018-01-02 falcon    361\n                   parrot     15\n\n        >>> df_multiindex.to_xarray()\n        <xarray.Dataset>\n        Dimensions:  (animal: 2, date: 2)\n        Coordinates:\n          * date     (date) datetime64[ns] 2018-01-01 2018-01-02\n          * animal   (animal) object 'falcon' 'parrot'\n        Data variables:\n            speed    (date, animal) int64 350 18 361 15\n        "
    try:
        import xarray
    except ImportError:
        raise ImportError('the xarray library is not installed\nyou can install via conda\nconda install xarray\nor via pip\npip install xarray\n')
    if (self.ndim == 1):
        return xarray.DataArray.from_series(self)
    elif (self.ndim == 2):
        return xarray.Dataset.from_dataframe(self)
    coords = [(a, self._get_axis(a)) for a in self._AXIS_ORDERS]
    return xarray.DataArray(self, coords=coords)
Return an xarray object from the pandas object.

Returns
-------
xarray.DataArray or xarray.Dataset
    Data in the pandas structure converted to Dataset if the object is
    a DataFrame, or a DataArray if the object is a Series.

See Also
--------
DataFrame.to_hdf : Write DataFrame to an HDF5 file.
DataFrame.to_parquet : Write a DataFrame to the binary parquet format.

Notes
-----
See the `xarray docs <http://xarray.pydata.org/en/stable/>`__

Examples
--------
>>> df = pd.DataFrame([('falcon', 'bird',  389.0, 2),
...                    ('parrot', 'bird', 24.0, 2),
...                    ('lion',   'mammal', 80.5, 4),
...                    ('monkey', 'mammal', np.nan, 4)],
...                    columns=['name', 'class', 'max_speed',
...                             'num_legs'])
>>> df
     name   class  max_speed  num_legs
0  falcon    bird      389.0         2
1  parrot    bird       24.0         2
2    lion  mammal       80.5         4
3  monkey  mammal        NaN         4

>>> df.to_xarray()
<xarray.Dataset>
Dimensions:    (index: 4)
Coordinates:
  * index      (index) int64 0 1 2 3
Data variables:
    name       (index) object 'falcon' 'parrot' 'lion' 'monkey'
    class      (index) object 'bird' 'bird' 'mammal' 'mammal'
    max_speed  (index) float64 389.0 24.0 80.5 nan
    num_legs   (index) int64 2 2 4 4

>>> df['max_speed'].to_xarray()
<xarray.DataArray 'max_speed' (index: 4)>
array([389. ,  24. ,  80.5,   nan])
Coordinates:
  * index    (index) int64 0 1 2 3

>>> dates = pd.to_datetime(['2018-01-01', '2018-01-01',
...                         '2018-01-02', '2018-01-02'])
>>> df_multiindex = pd.DataFrame({'date': dates,
...                    'animal': ['falcon', 'parrot', 'falcon',
...                               'parrot'],
...                    'speed': [350, 18, 361, 15]}).set_index(['date',
...                                                    'animal'])
>>> df_multiindex
                   speed
date       animal
2018-01-01 falcon    350
           parrot     18
2018-01-02 falcon    361
           parrot     15

>>> df_multiindex.to_xarray()
<xarray.Dataset>
Dimensions:  (animal: 2, date: 2)
Coordinates:
  * date     (date) datetime64[ns] 2018-01-01 2018-01-02
  * animal   (animal) object 'falcon' 'parrot'
Data variables:
    speed    (date, animal) int64 350 18 361 15
def to_xarray(self):
    "\n        Return an xarray object from the pandas object.\n\n        Returns\n        -------\n        xarray.DataArray or xarray.Dataset\n            Data in the pandas structure converted to Dataset if the object is\n            a DataFrame, or a DataArray if the object is a Series.\n\n        See Also\n        --------\n        DataFrame.to_hdf : Write DataFrame to an HDF5 file.\n        DataFrame.to_parquet : Write a DataFrame to the binary parquet format.\n\n        Notes\n        -----\n        See the `xarray docs <http://xarray.pydata.org/en/stable/>`__\n\n        Examples\n        --------\n        >>> df = pd.DataFrame([('falcon', 'bird',  389.0, 2),\n        ...                    ('parrot', 'bird', 24.0, 2),\n        ...                    ('lion',   'mammal', 80.5, 4),\n        ...                    ('monkey', 'mammal', np.nan, 4)],\n        ...                    columns=['name', 'class', 'max_speed',\n        ...                             'num_legs'])\n        >>> df\n             name   class  max_speed  num_legs\n        0  falcon    bird      389.0         2\n        1  parrot    bird       24.0         2\n        2    lion  mammal       80.5         4\n        3  monkey  mammal        NaN         4\n\n        >>> df.to_xarray()\n        <xarray.Dataset>\n        Dimensions:    (index: 4)\n        Coordinates:\n          * index      (index) int64 0 1 2 3\n        Data variables:\n            name       (index) object 'falcon' 'parrot' 'lion' 'monkey'\n            class      (index) object 'bird' 'bird' 'mammal' 'mammal'\n            max_speed  (index) float64 389.0 24.0 80.5 nan\n            num_legs   (index) int64 2 2 4 4\n\n        >>> df['max_speed'].to_xarray()\n        <xarray.DataArray 'max_speed' (index: 4)>\n        array([389. ,  24. ,  80.5,   nan])\n        Coordinates:\n          * index    (index) int64 0 1 2 3\n\n        >>> dates = pd.to_datetime(['2018-01-01', '2018-01-01',\n        ...                         '2018-01-02', '2018-01-02'])\n        >>> df_multiindex = pd.DataFrame({'date': dates,\n        ...                    'animal': ['falcon', 'parrot', 'falcon',\n        ...                               'parrot'],\n        ...                    'speed': [350, 18, 361, 15]}).set_index(['date',\n        ...                                                    'animal'])\n        >>> df_multiindex\n                           speed\n        date       animal\n        2018-01-01 falcon    350\n                   parrot     18\n        2018-01-02 falcon    361\n                   parrot     15\n\n        >>> df_multiindex.to_xarray()\n        <xarray.Dataset>\n        Dimensions:  (animal: 2, date: 2)\n        Coordinates:\n          * date     (date) datetime64[ns] 2018-01-01 2018-01-02\n          * animal   (animal) object 'falcon' 'parrot'\n        Data variables:\n            speed    (date, animal) int64 350 18 361 15\n        "
    try:
        import xarray
    except ImportError:
        raise ImportError('the xarray library is not installed\nyou can install via conda\nconda install xarray\nor via pip\npip install xarray\n')
    if (self.ndim == 1):
        return xarray.DataArray.from_series(self)
    elif (self.ndim == 2):
        return xarray.Dataset.from_dataframe(self)
    coords = [(a, self._get_axis(a)) for a in self._AXIS_ORDERS]
    return xarray.DataArray(self, coords=coords)