convert n-dim array to pandas dataframe
Open
Nobody has claimed this yet.
topic-documentation
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
I just noticed that doing
da = xr.DataArray(np.random.rand(10, 10, 10), dims=('a', 'b', 'c'))
da.to_pandas()
gives
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~/local/bin/anaconda3/envs/test_env/lib/python3.8/site-packages/xarray/core/dataarray.py in to_pandas(self)
2397 try:
-> 2398 constructor = constructors[self.ndim]
2399 except KeyError:
KeyError: 3
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-22-2c9fae875981> in <module>
----> 1 da.to_pandas()
~/local/bin/anaconda3/envs/test_env/lib/python3.8/site-packages/xarray/core/dataarray.py in to_pandas(self)
2398 constructor = constructors[self.ndim]
2399 except KeyError:
-> 2400 raise ValueError(
2401 "cannot convert arrays with %s dimensions into "
2402 "pandas objects" % self.ndim
ValueError: cannot convert arrays with 3 dimensions into pandas objects
It is worth raising a suggestion (see below)? Or could you even do da.to_dataset(name='da').to_dataframe() under the hood. I feel the output would be what the user expects but I imagine that is not always true
da.to_dataset(name='da').to_dataframe()

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the DataArray.to_pandas() entry point and compare its current behavior with da.to_dataset(name='da').to_dataframe() for the three-dimensional example. First confirm whether n-dimensional conversion is intended and what output users should expect; done means an agreed behavior implemented and covered for this example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100