Closed
Description
I am playing with xarray (moving away from pandas panel) but I cannot get my head around the following example. I create a multiindex panel and then convert it to a dataarray. I would like then to slice as I used to do in pandas , but trying the equivalent it fails with TypeError: '(slice(None, None, None), [3])' is an invalid key
Similarly I cannot get x.sel(major_axis=?) to work trying to achieve the same result.
import numpy as np
import pandas as pd
import xarray as xr
columns=['A','B','C']
index=pd.MultiIndex.from_product([['a','b','c','d'],[1,2,3]])
items=['x','y','z']
z=pd.Panel.from_dict({i:pd.DataFrame(data=np.random.rand(12,3),index=index,columns=columns) for i in items})
z.loc[:,(slice(None),[3]),'A'] #<-- That's what I want to do in xarray
x=z.to_xarray()
x.loc[:,(slice(None),[3]),'A'] #<- It fails
Do you have any insight?
Metadata
Metadata
Assignees
Labels
No labels