Python: Array(Matrix) to Pandas DataFrame -


i stuck trying convert array pandas dataframe.

my output array looks this:

[[1,2,4,n],[1,2,3,n]] 

example output:

[[0.04376367614879647, 0.04376367614879649, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.08096280087527355, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.04376367614879651, 0.043763676148796504, 0.043763676148796504], [0.04376367614879647, 0.04376367614879649, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.08096280087527355, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.043763676148796504, 0.04376367614879651, 0.043763676148796504, 0.043763676148796504],...[]] 

now create dataframe columns each 1..n value. best way tell pandas this?

my_dataframe = pd.dataframe(my_array,columns=['first','second',...n] 

i having trouble reshaping my_array, pandas can understand.

thank help

there .t() method it:

in [8]:  arr = [[1,2,3,5],[2,3,4,6]] print pd.dataframe(arr, index=['col1','col2']).t    col1  col2 0     1     2 1     2     3 2     3     4 3     5     6 

if input numpy array:

in [9]:  arr = np.array([[1,2,3,5],[2,3,4,6]]) print pd.dataframe(arr.t, columns=['col1','col2'])    col1  col2 0     1     2 1     2     3 2     3     4 3     5     6 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -