graphlab adding variable columns from existing sframe
<p>I have a SFrame e.g.</p>

<pre><code>a | b
-----
2 | 31 4 5
0 | 1 9
1 | 2 84
</code></pre>

<p>now i want to get following result</p>

<pre><code>a | b      | c | d | e
----------------------
2 | 31 4 5 | 31|4  | 5
0 | 1 9    | 1 | 9 | 0
1 | 2 84   | 2 | 84 | 0
</code></pre>

<p>any idea how to do it?  or maybe i have to use some other tools? </p>

<p>thanks</p>

<p>Using pandas:</p>

<pre><code>In [409]: sf
Out[409]: 
Columns:
    a   int
    b   str

Rows: 3

Data:
+---+--------+
| a |   b    |
+---+--------+
| 2 | 31 4 5 |
| 0 |  1 9   |
| 1 |  2 84  |
+---+--------+
[3 rows x 2 columns]

In [410]: df = sf.to_dataframe()

In [411]: newdf =  pd.DataFrame(df.b.str.split().tolist(), columns = ['c', 'd', 'e']).fillna('0')

In [412]: df.join(newdf)
Out[412]: 
   a       b   c   d  e
0  2  31 4 5  31   4  5
1  0     1 9   1   9  0
2  1    2 84   2  84  0
</code></pre>

<p>Converting back to SFrame:</p>

<pre><code>In [498]: SFrame(df.join(newdf))
Out[498]: 
Columns:
    a   int
    b   str
    c   str
    d   str
    e   str

Rows: 3

Data:
+---+--------+----+----+---+
| a |   b    | c  | d  | e |
+---+--------+----+----+---+
| 2 | 31 4 5 | 31 | 4  | 5 |
| 0 |  1 9   | 1  | 9  | 0 |
| 1 |  2 84  | 2  | 84 | 0 |
+---+--------+----+----+---+
[3 rows x 5 columns]
</code></pre>

<p>If you want integers/floats, you can also do:</p>

<pre><code>In [506]: newdf =  pd.DataFrame(map(lambda x: [int(y) for y in x], df.b.str.split().tolist()), columns = ['c', 'd', 'e'])

In [507]: newdf
Out[507]: 
    c   d    e
0  31   4  5.0
1   1   9  NaN
2   2  84  NaN

In [508]: SFrame(df.join(newdf))
Out[508]: 
Columns:
    a   int
    b   str
    c   int
    d   int
    e   float

Rows: 3

Data:
+---+--------+----+----+-----+
| a |   b    | c  | d  |  e  |
+---+--------+----+----+-----+
| 2 | 31 4 5 | 31 | 4  | 5.0 |
| 0 |  1 9   | 1  | 9  | nan |
| 1 |  2 84  | 2  | 84 | nan |
+---+--------+----+----+-----+
[3 rows x 5 columns]
</code></pre>

python pandas graphlab