I have a numpy array data. Here is its shape:
data.shape
(223,12,437)
I want to make a dataframe out of this array. I want the data frame to have:
223rows1column- Each element is a np.array with shape
(12,437).
When I run:
pd.DataFrame(data)
I get this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-55-cd168f76d566> in <module>
----> 1 pd.DataFrame(data)
~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
676 dtype=dtype,
677 copy=copy,
--> 678 typ=manager,
679 )
680
~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in ndarray_to_mgr(values, index, columns, dtype, copy, typ)
302 # by definition an array here
303 # the dtypes will be coerced to a single dtype
--> 304 values = _prep_ndarray(values, copy=copy)
305
306 if dtype is not None and not is_dtype_equal(values.dtype, dtype):
~/anaconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py in _prep_ndarray(values, copy)
553 values = values.reshape((values.shape[0], 1))
554 elif values.ndim != 2:
--> 555 raise ValueError(f"Must pass 2-d input. shape={values.shape}")
556
557 return values
ValueError: Must pass 2-d input. shape=(223, 12, 437)
Why is this? Doesn't the 0th element in the shape tuple (223,) contain the information for how many rows to make the df?
What should I do instead?
pandas.DataFrameis 2D.