Alessandro Melo
Alessandro Melo

Reputation: 150

Creating dataframe from numpy arrays

I have a dataframe, where each row describe a matrix (3,3):

enter image description here

I transformed this dataframe in multiple matrices, to do some matrices operations with them. I used the code:

df.to_numpy().reshape(-1,3,3)

Which returned:

enter image description here

This is exactly what I wanted but, after finished the operations with the matrices, I need to transform all of these matrices in the original form of the dataframe, like in the first image. How can I do this? There's some analogue function to .to_numpy()? I tried pd.DataFrame(array) but don't worked.

d = pd.DataFrame(array)
ValueError: Must pass 2-d input

Upvotes: 0

Views: 69

Answers (1)

Stuart Berg
Stuart Berg

Reputation: 18141

Try:

array_2d = array.reshape((-1, 9))
d = pd.DataFrame(array_2d)

Upvotes: 1

Related Questions