Closed
Description
In [1]: import xarray as xr
In [2]: import pandas as pd
In [3]: df = pd.DataFrame({'a': pd.np.random.rand(10), 'b': pd.np.random.rand(10)})
In [4]: df
Out[4]:
a b
0 0.711341 0.636954
1 0.199090 0.370938
2 0.486677 0.274427
3 0.407370 0.282419
4 0.760676 0.069163
5 0.098402 0.820085
6 0.710977 0.777998
7 0.687722 0.764163
8 0.297734 0.740927
9 0.554381 0.388324
In [5]: xr.Dataset(df)
Out[5]:
<xarray.Dataset>
Dimensions: (dim_0: 10)
Coordinates:
* dim_0 (dim_0) int64 0 1 2 3 4 5 6 7 8 9
Data variables:
a (dim_0) float64 0.7113 0.1991 0.4867 0.4074 0.7607 0.0984 0.711 ...
b (dim_0) float64 0.637 0.3709 0.2744 0.2824 0.06916 0.8201 0.778 ...
In [6]: pd.DataFrame(xr.Dataset(df))
---------------------------------------------------------------------------
PandasError Traceback (most recent call last)
<ipython-input-6-be1c7b096414> in <module>()
----> 1 pd.DataFrame(xr.Dataset(df))
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
303 copy=False)
304 else:
--> 305 raise PandasError('DataFrame constructor not properly called!')
306
307 NDFrame.__init__(self, mgr, fastpath=True)
PandasError: DataFrame constructor not properly called!
I think because this looks for dict
rather than 'dict-like' or Mapping
: https://github.com/pydata/pandas/blob/master/pandas/core/frame.py#L222