将二维数组分配给panda数据框

时间:2019-04-24 16:51:28

标签: python pandas

我想将二维数组分解为1维数组,并将其分配给熊猫数据框。在这方面需要帮助

This is my panda data frame. 

 Id       Dept            Date

100    Healthcare        2007-01-03
100    Healthcare        2007-01-10
100    Healthcare        2007-01-17

Two dimensional array looks like

array([[10, 20, 30],
       [40, 50, 60],
       [70, 80, 90]])

输出为。

 Id       Dept            Date                vect

100    Healthcare        2007-01-03          [10, 20, 30]
100    Healthcare        2007-01-10          [40, 50, 60]
100    Healthcare        2007-01-17          [70, 80, 90]

1 个答案:

答案 0 :(得分:1)

您可以通过使用arraylist转换为tolist来实现这一点

df['vect']=ary.tolist()
df
Out[281]: 
    Id        Dept        Date          vect
0  100  Healthcare  2007-01-03  [10, 20, 30]
1  100  Healthcare  2007-01-10  [40, 50, 60]
2  100  Healthcare  2007-01-17  [70, 80, 90]