I have a 2D NumPy array of structs:
arr = np.zeros((3,5), [('x',int), ('y',float)])
That is:
array([[(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)],
[(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)],
[(0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0), (0, 0.0)]],
dtype=[('x', '<i8'), ('y', '<f8')])
I want to create a Pandas Panel from it. I tried the obvious:
pd.Panel(arr)
ValueError: The number of dimensions required is 3, but the number of dimensions of the ndarray given was 2
Then I discovered this hideous pile:
pd.Panel(dict(enumerate(pd.DataFrame(a) for a in arr)))
It produces:
<class 'pandas.core.panel.Panel'>
Dimensions: 3 (items) x 5 (major_axis) x 2 (minor_axis)
Items axis: 0 to 2
Major_axis axis: 0 to 4
Minor_axis axis: x to y
This "works" but is very inefficient and an eyesore.
How are such Panels meant to be constructed?
Edit: I submitted an issue here: https://github.com/pandas-dev/pandas/issues/14511