Reputation: 524
Our objective is to create a data frame with a shape of (2,3,2) as follows:
first index or 2 = row in the data frame
second index or 3 = columns in the data frame
third index or 2 = values in those rows and columns.
Our data:
data = np.array([[[1,3],[5,7],[9,11]],[[2,4],[6,8],[10,12]]])
print(data.shape)
print("=====================================")
data
When add to a data frame as codes below:
df_sample = pd.DataFrame(data,columns=['A','B','C'])
it shows: ValueError: Must pass 2-d input. shape=(2, 3, 2)
or can see as an image below:
Upvotes: 3
Views: 21041
Reputation: 571
Does this work?
data = np.array([[[1,3],[5,7],[9,11]],[[2,4],[6,8],[10,12]]])
pd.DataFrame(data.tolist(), columns=['A','B','C'])
returns
A B C
0 [1, 3] [5, 7] [9, 11]
1 [2, 4] [6, 8] [10, 12]
Upvotes: 4