2016-08-23 66 views
2

我有兩列字符串。現在讓我們說col1和col2 現在我們如何使用graphlab SFrame將col1和col2的內容組合到col3中?graphlab創建框架結合兩列

col1 col2 
23 33 
42 11 
........ 

col3 
23,33 
42,11 
.... 

拆散只會給sarray或快譯通,我只有一個詞的袋子

試圖

user_info['X5']=user_info['X3'].apply(lambda x:x+','+user_info['X4'].apply(lambda y:y)) 

不似乎是正確的

有什麼想法?

回答

3

使用熊貓:

In [271]: df 
Out[271]: 
    col1 col2 
0 23 33 
1 42 11 

In [272]: df['col3'] = (df['col1'].map(str) + ',' + df['col2'].map(str)) 

In [273]: df 
Out[273]: 
    col1 col2 col3 
0 23 33 23,33 
1 42 11 42,11 

使用graphlab:

In [17]: sf 
Out[17]: 
Columns: 
    col1 int 
    col2 int 

Rows: 2 

Data: 
+------+------+ 
| col1 | col2 | 
+------+------+ 
| 23 | 33 | 
| 42 | 11 | 
+------+------+ 
[2 rows x 2 columns] 

In [18]: sf['col3'] = sf['col1'].apply(str) + ',' + sf['col2'].apply(str) 

In [19]: sf 
Out[19]: 
Columns: 
    col1 int 
    col2 int 
    col3 str 

Rows: 2 

Data: 
+------+------+-------+ 
| col1 | col2 | col3 | 
+------+------+-------+ 
| 23 | 33 | 23,33 | 
| 42 | 11 | 42,11 | 
+------+------+-------+ 
[2 rows x 3 columns] 
+0

是的,但我們如何能做到這一點的graphlab雖然創造? – ikel

+0

@ikel我已經更新了答案。 –

+0

我看,測試工作。爲什麼適用(str)?它可以適用(int)? – ikel