How to convert Numpy array to Panda DataFrame

前端 未结 4 1957
春和景丽
春和景丽 2021-01-04 05:39

I have a Numpy array that looks like this:

[400.31865662]
[401.18514808]
[404.84015554]
[405.14682194]
[405.67735105]
[273.90969447]
[274.0894528]

4条回答
  •  伪装坚强ぢ
    2021-01-04 06:06

    I just figured out my mistake. (data) was a list of arrays:

    [array([400.0290173]), array([400.02253235]), array([404.00252113]), array([403.99466754]), array([403.98681395]), array([271.97896036]), array([271.97110677])]
    

    So I used np.vstack(data) to concatenate it

    conc = np.vstack(data)
    
    [[400.0290173 ]
     [400.02253235]
     [404.00252113]
     [403.99466754]
     [403.98681395]
     [271.97896036]
     [271.97110677]]
    

    Then I convert the concatened array into a Pandas Dataframe by using the

    newdf = pd.DataFrame(conc)
    
    
        0
    0  400.029017
    1  400.022532
    2  404.002521
    3  403.994668
    4  403.986814
    5  271.978960
    6  271.971107
    

    Et voilà!

提交回复
热议问题