pandas 1.4.2

NotesReturns
to_xarray(self)

Notes

See the xarray docs

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.

Return an xarray object from the pandas object.

See Also

DataFrame.to_hdf

Write DataFrame to an HDF5 file.

DataFrame.to_parquet

Write a DataFrame to the binary parquet format.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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
This example is valid syntax, but we were not able to check execution
>>> 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
This example is valid syntax, but we were not able to check execution
>>> 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
This example is valid syntax, but we were not able to check execution
>>> 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]})
... df_multiindex = df_multiindex.set_index(['date', 'animal'])
This example is valid syntax, but we were not able to check execution
>>> df_multiindex
                   speed
date       animal
2018-01-01 falcon    350
           parrot     18
2018-01-02 falcon    361
           parrot     15
This example is valid syntax, but we were not able to check execution
>>> 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
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/generic.py#3096
type: <class 'function'>
Commit: