2017-04-21 115 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 
相關問題