How to convert Numpy array to Panda DataFrame

前端 未结 4 2081
春和景丽
春和景丽 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:20

    You could flatten the numpy array:

    import numpy as np
    import pandas as pd
    
    data = [[400.31865662],
            [401.18514808],
            [404.84015554],
            [405.14682194],
            [405.67735105],
            [273.90969447],
            [274.0894528]]
    
    arr = np.array(data)
    
    df = pd.DataFrame(data=arr.flatten())
    
    print(df)
    

    Output

                0
    0  400.318657
    1  401.185148
    2  404.840156
    3  405.146822
    4  405.677351
    5  273.909694
    6  274.089453
    

提交回复
热议问题