ENH: add to_xarray conversion method
State: closed

supersedes #11950 
xref #10000 

using `xarray` >= 07.0

```
In [10]: Series([1,2,3]).to_xarray()
Out[10]: 
<xarray.DataArray (index: 3)>
array([1, 2, 3])
Coordinates:
  * index    (index) int64 0 1 2

In [11]: DataFrame({'A' : [1,2,3], 'B' : ['foo','bar','baz']}).to_xarray()
Out[11]: 
<xarray.Dataset>
Dimensions:  (index: 3)
Coordinates:
  * index    (index) int64 0 1 2
Data variables:
    A        (index) int64 1 2 3
    B        (index) object 'foo' 'bar' 'baz'

In [14]: Panel(np.random.randn(2, 3, 4)).to_xarray()
Out[14]: 
<xarray.DataArray (items: 2, major_axis: 3, minor_axis: 4)>
array([[[ 0.23726039,  0.44636322,  0.04425575,  1.06178388],
        [-0.58236405,  0.62602167,  0.36156612, -0.12687913],
        [-0.67854107,  0.72270844, -1.15402631, -1.89758909]],

       [[ 0.42948622,  0.93227075, -0.13943692,  0.83043343],
        [ 1.0355157 , -0.30532004, -0.16337369, -0.29283026],
        [ 0.65199775, -0.11131818,  0.37853134,  1.56620844]]])
Coordinates:
  * items       (items) int64 0 1
  * major_axis  (major_axis) int64 0 1 2
  * minor_axis  (minor_axis) int64 0 1 2 3
```

TODO:
- [ ] examples in doc-string
- [ ] how-to-convert/use xarray


Labels:
name: Enhancement
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
since I renamed the branch now really sure if there was a way to avoid creating a new PR. oh well.

@shoyer ping when releasing new `xarray`. I am going to min-version this to what you release.

@MaximilianR it would be quite helpful if you can post / write a mini-doc (where we can incorporate in a doc-string / document) on how to migrate `Panel` -> `xarray`, with use-cases / how-tos etc.

can obviously also add to here:  http://xray.readthedocs.org/en/stable/pandas.html 

@jreback Yes I can have a go at that. I could see that being fairly short given the existing docs - just a couple of examples of Panel migration. Is that what you envision?

@MaximilianR yep, the migration part as well as 'working' with them (which might require another section). E.g. imagine you have `Panels` and now  you have xarray objects. So they want to perform 'typical' operations there (we will prob need a section in the pandas docs when I do the deprecation PR's) as well (so will effectively just copy what is there).

@shoyer @MaximilianR 

updated to use `xarray` 0.7.0

works with all index types including MultiIndex! nice!
Panel <-> xarray <-> Panel works nicely!
`>3` dim doesn't convert back to pandas (but no problem)

I think you need to have RTD use `xarray`? (and have a pointer from `xray`)?

@jreback I'm suggesting http://xarray.pydata.org/ instead... it turns out you can't change RTD stubs, so we're stuck with http://xray.readthedocs.org for now.

comments 

@wesm @jorisvandenbossche @TomAugspurger @sinhrks @cpcloud 

@shoyer note that conda has updated to include `xarray`

@jreback @shoyer I've done a (currently very short & basic) draft of how to move from pandas to xarray, with the intention you guys can offer some feedback and we can iterate.

Do you want me to do a separate PR into pandas? Or should this go into the 'from Pandas' section of the xarray docs, with a link from pandas' What's New?

@MaximilianR I think best is to add to the `xray` docs, which we will link to.

Personally I think this maybe more belongs in the pandas docs. I mean, the xarray docs could certainly have a section about how it interplays with pandas (as it already has, http://xarray.pydata.org/en/stable/pandas.html), but as this will also be about how to move from the deprecated panel to xarray, it feels more at place in the pandas docs (I don't think xarray docs should handle about deprecated pandas features).

Anyhow, not that important, as just link to wherever it is located.

@jorisvandenbossche right, I have a note about that above, e.g. about how to transition from using a `Panel` to a `DataArray`. 

So @MaximilianR can certainly add to the pandas docs (but should obviously add to xarray as well)

@shoyer was just about to merge. anything else besides those 2 comments?

(and the linked issue for more docs)

@jorisvandenbossche I think I broke the doc build, but not sure how: https://travis-ci.org/pydata/pandas/jobs/108337474