Problem
As an example, consider the following structured numpy array (containing sub-arrays):
data = [
(1, (5., 3., 7.), 6),
(2, (2., 1., 3.), 9),
(3, (3., 8., 4.), 3),
(4, (1., 7., 4.), 2),
]
dtype = [('A', '<i8'), ('B', '<f8', (3,)), ('C', '<i8')]
arr = np.array(data, dtype=dtype)
I would like to convert this array arr into a pandas dataframe that looks like this:
A B_1 B_2 B_3 C
0 1 5.0 3.0 7.0 6
1 2 2.0 1.0 3.0 9
2 3 3.0 8.0 4.0 3
3 4 1.0 7.0 4.0 2
Tried thus far
I've tried to use pandas' method from_records to perform the conversion:
df = pd.DataFrame.from_records(arr)
but this throws the error Exception: Data must be 1-dimensional.
Question
What would be a good way to perform such a conversion to pandas dataframe?