Skip to content

Commit

Permalink
DOC: better to_xarray doc-string
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Feb 10, 2016
1 parent e78c61f commit 4404d39
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,15 @@ def to_xarray(self):
Examples
--------
>>> df = DataFrame({'A' : [1, 2, 3], 'B' : ['foo', 'bar', 'baz']})
>>> df = pd.DataFrame({'A' : [1, 2, 3],
'B' : ['foo', 'bar', 'baz'],
'C' : np.arange(4.,7)})
>>> df
A B C
0 1 foo 4.0
1 2 bar 5.0
2 3 baz 6.0
>>> df.to_xarray()
<xarray.Dataset>
Dimensions: (index: 3)
Expand All @@ -1061,26 +1069,41 @@ def to_xarray(self):
Data variables:
A (index) int64 1 2 3
B (index) object 'foo' 'bar' 'baz'
C (index) float64 4.0 5.0 6.0
>>> p = pd.Panel(np.arange(24).reshape(4,3,2),
items=list('ABCD'),
major_axis=pd.date_range('20130101', periods=3),
minor_axis=['first', 'second'])
>>> p
<class 'pandas.core.panel.Panel'>
Dimensions: 4 (items) x 3 (major_axis) x 2 (minor_axis)
Items axis: A to D
Major_axis axis: 2013-01-01 00:00:00 to 2013-01-03 00:00:00
Minor_axis axis: first to second
>>> p = pd.Panel(np.arange(6).reshape(3,2,1))
>>> p.to_xarray()
<xarray.DataArray (items: 3, major_axis: 2, minor_axis: 1)>
array([[[0],
[1]],
[[2],
[3]],
[[4],
[5]]])
<xarray.DataArray (items: 4, major_axis: 3, minor_axis: 2)>
array([[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10, 11]],
[[12, 13],
[14, 15],
[16, 17]],
[[18, 19],
[20, 21],
[22, 23]]])
Coordinates:
* items (items) int64 0 1 2
* major_axis (major_axis) int64 0 1
* minor_axis (minor_axis) int64 0
* items (items) object 'A' 'B' 'C' 'D'
* major_axis (major_axis) datetime64[ns] 2013-01-01 2013-01-02 2013-01-03 # noqa
* minor_axis (minor_axis) object 'first' 'second'
Notes
-----
See also the `xarray docs <http://xarray.pydata.org/en/stable/>`__
See the `xarray docs <http://xarray.pydata.org/en/stable/>`__
"""
import xarray
if self.ndim == 1:
Expand Down

0 comments on commit 4404d39

Please sign in to comment.