2

I have a loop printing out arrays of the form [[1,2,3,...100]] [[3,4,5, ...102]]and so on. I need each of the [[---]] to be a separate column in a dataframe. I tried to append them into a list but it is harder to add a 3D array to a dataframe. Could someone please suggest an alternative?

1 Answer 1

4

Try:

a=[[1,2,3],[4,5,6]]
pd.DataFrame(np.array(a).transpose())

Output:

   0  1
0  1  4
1  2  5
2  3  6

Per Comments below:

a = [np.array([[ 1,2,3]]), np.array([[3,4,5]])]

pd.DataFrame(np.vstack(a).T)
Sign up to request clarification or add additional context in comments.

2 Comments

It gives this error: ValueError: Must pass 2-d input.
When it is in the form of an appended list, it looks like this: [array([[ 1,2,3]]), array([[3,4,5]])]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.