How do i convert a numpy array to a pandas dataframe?
for example:
test = np.array([[1,2],[2,3]])
test2 = np.array([[2,4],[2,5]])
to this:
pd.DataFrame({'test':[[1,2],[2,3]],
'test2':[[2,4],[2,5]]})
test test2
0 [1, 2] [2, 4]
1 [2, 3] [2, 5]
Although you could use
In [85]: pd.DataFrame({'test':test.tolist(), 'test2':test2.tolist()})
Out[85]:
test test2
0 [1, 2] [2, 4]
1 [2, 3] [2, 5]
computation on the NumPy arrays would probably be much faster than an equivalent computation done on a Pandas DataFrame whose columns contain Python lists.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments