How to convert Numpy array to Panda DataFrame

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

    There is another way, which isn't mentioned in the other answers. If you have a NumPy array which is essentially a row vector (or column vector) i.e. shape like (n, ) , then you could do the following :

    # sample array
    x = np.zeros((20))
    # empty dataframe
    df = pd.DataFrame()
    # add the array to df as a column
    df['column_name'] = x
    

    This way you can add multiple arrays as separate columns.

提交回复
热议问题