2016-08-23 6 views
2

Ich habe zwei Spalten mit Strings. sagen wir mal col1 und col2 wie können wir nun den Inhalt von col1 und col2 in col3 mit graphlab SFrame kombinieren?graphlab create sframe kombinieren zwei Spalte

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

in

col3 
23,33 
42,11 
.... 

Entstapelungsunterdrückung geben nur SFeld oder dict, i man nur eine Tüte Wörter

versucht

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

tut richtig zu sein scheinen

eine Idee?

Antwort

3

Mit Pandas:

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 

Mit 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

ja, aber wie können wir tun es aber in graphlab schaffen? – ikel

+0

@ikel Ich habe die Antwort aktualisiert. –

+0

ich sehe, geprüfte Arbeit. Warum bewerben (str)? kann es gelten (int)? – ikel