2017-04-21 118 views
1
Feature1          Feature2 
    [0.0450819672, 0.0450819672, 0.0081967213] 8.236613 
    [0.0551181102, 0.0551181102, 0.0078740157] 7.954549 

我想将Feature2的类型为float64添加到Feature1数组的末尾。 这是我试图实现它,但Feature2_1似乎是一个空的列。在熊猫数据框中添加一个元素到数组的末尾

df_2['Feature2_1'] = '' 
    for index, row in df.iterrows(): 
    print row[df['Feature2']] 
    value = row[df_2['Feature2']] 
    df_2.set_value(index,'Feature2_1',value) 

任何意见将非常感谢!

回答

4

试试这个:

In [99]: df 
Out[99]: 
            Feature1 Feature2 
0 [0.0450819672, 0.0450819672, 0.0081967213] 8.236613 
1 [0.0551181102, 0.0551181102, 0.0078740157] 7.954549 

In [100]: df.Feature1 += df.Feature2.apply(lambda x: [x]) 

In [101]: df 
Out[101]: 
               Feature1 Feature2 
0 [0.0450819672, 0.0450819672, 0.0081967213, 8.236613] 8.236613 
1 [0.0551181102, 0.0551181102, 0.0078740157, 7.954549] 7.954549 
相关问题