I've been baffled on how to select a specific row within a SFrame array. I'm able to select the first row here:
sf
+-------------------------------+
| X1 |
+-------------------------------+
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
[100 rows x 1 columns]
sf[:1]
+-------------------------------+
| X1 |
+-------------------------------+
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
[1 rows x 1 columns]
sf[:2]
+-------------------------------+
| X1 |
+-------------------------------+
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
| [0.0, 0.0, 0.0, 0.0, 0.0, ... |
[2 rows x 1 columns]
type(sf[:1])
graphlab.data_structures.sframe.SFrame
Here I tried to get just row 2
sf[:,2]
# TypeError: Invalid key type: must be str, bytes or type
How could I select any row in the dataframe?
You can select a row with:
import graphlab as gl
sf = gl.SFrame({'a':[1,2,3], 'b':[2,9,1]})
# select first row
print sf[0]
# select second row
print sf[1]
# and so on
# convert first row to an SFrame
sf_one_raw = sf[0:1]
# convert second row to an SFrame
sf_one_raw = sf[1:2]