-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
Code Sample
import xarray as xr
import numpy as np
data = xr.DataArray(np.random.randn(2, 3), coords={'x': ['a', 'b']}, dims=('y', 'x'))
ds = xr.Dataset({'foo': data})
# Applied on the Dataset
ds.to_dataframe()
# foo
#x y
#a 0 0.348519
# 1 -0.322634
# 2 -0.683181
#b 0 0.197501
# 1 0.504810
# 2 -1.871626
# Applied to the DataArray
ds['foo'].to_dataframe()
# foo
#y x
#0 a 0.348519
# b 0.197501
#1 a -0.322634
# b 0.504810
#2 a -0.683181
# b -1.871626Problem description
The to_dataframe method applied to a DataArray will respect the dimensions order whereas the same method applied to a Dataset will use an alphabetically sorted order.
In both situation to_dataframe calls _to_dataframe() with an argument.
The DataArray uses an OrderedDict but the Dataset uses self.dims (which is a SortedKeyDict) as argument.