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
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)
2 Comments
jazzytortoise
It gives this error: ValueError: Must pass 2-d input.
jazzytortoise
When it is in the form of an appended list, it looks like this: [array([[ 1,2,3]]), array([[3,4,5]])]