Reputation: 73
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?
Upvotes: 2
Views: 287
Reputation: 153460
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
a = [np.array([[ 1,2,3]]), np.array([[3,4,5]])]
pd.DataFrame(np.vstack(a).T)
Upvotes: 4