0

How are the values sorted when I use row.values() in an graphlab.SFrame row?

For example:

import graphlab as gl
x = gl.SFrame({'X200':[1,2,3], 'X100':[4,5,6], 'X1': [7,8,9]})
row = x[0] # first row
print row.values()

[out]:

[ 7, 4, 1]

So it seems like they are sorted by the key / column names, but is that always true? Any pointers to documentation from python dictionary or SFrame will be much appreciated.

alvas
  • 115,346
  • 109
  • 446
  • 738

2 Answers2

1

No the row.values() will not return a sorted list since row is a python dictionary and it is unsorted.

To prove the point:

>>> x = gl.SFrame({'X1': ['foo', 'bar', 'blah'], 'X3':[1,2,3], 'X2':[4,5,6]})
>>> x[0].values()[1:]
[1, 'foo']

It seems like to get a sorted values, you would have to do some key sorting first:

>>> _, v = zip(*sorted(x[0].items())[1:])
>>> v
(4, 1)
alvas
  • 115,346
  • 109
  • 446
  • 738
0

This is more of a Python dictionary issue (see Key Order in Python Dictionaries). In python, the .values() method returns values in arbitrary order. A row of the SFrame is a dictionary.

Community
  • 1
  • 1
srikris
  • 126
  • 3