Error creating SFrame from a dictionary

User 3245 | 2/24/2016, 9:51:21 PM

This seems basic, but I found that SFrame creation fails if I give it an argument that is a Python dictionary with ints as values, strings as keys. Am I missing something obvious?

dict = {'fantastic': 932, 'love': 42065, 'bad': 3724, 'awesome': 2090, 'great': 45206, 'terrible': 748, 'amazing': 1363, 'horrible': 734, 'awful': 383, 'hate': 1220, 'wow': 144}

In [4]:

sf = graphlab.SFrame(dict) [INFO] GraphLab Create v1.8.3 started. Logging: /tmp/graphlabserver1456349820.log


TypeError Traceback (most recent call last) <ipython-input-4-9db4d38b80aa> in <module>() ----> 1 sf = graphlab.SFrame(dict)

/Users/davidr/anaconda/envs/dato-env/lib/python2.7/site-packages/graphlab/datastructures/sframe.pyc in init(self, data, format, proxy) 935 pass 936 else: --> 937 raise ValueError('Unknown input type: ' + format) 938 939 sframe_size = -1

/Users/davidr/anaconda/envs/dato-env/lib/python2.7/site-packages/graphlab/cython/context.pyc in exit(self, exctype, excvalue, traceback) 47 if not self.showcythontrace: 48 # To hide cython trace, we re-raise from here ---> 49 raise exctype(excvalue) 50 else: 51 # To show the full trace, we do nothing and let exception propagate

TypeError: object of type 'int' has no len()

Comments

User 19 | 2/24/2016, 10:14:16 PM

Unfortunately we don't accept this input directly. You need to instead do something like the following:

`

d = {'fantastic': 932, 'love': 42065, 'bad': 3724, 'awesome': 2090, 'great': 45206, 'terrible': 748, 'amazing': 1363, 'horrible': 734, 'awful': 383, 'hate': 1220, 'wow': 144} gl.SFrame({'word': d.keys(), 'value': d.values()})

Columns: value int word str

Rows: 11

Data: +-------+-----------+ | value | word | +-------+-----------+ | 932 | fantastic | | 42065 | love | | 2090 | awesome | | 748 | terrible | | 383 | awful | | 1220 | hate | | 45206 | great | | 144 | wow | | 3724 | bad | | 1363 | amazing | +-------+-----------+ `

Please let me know if that helps!

Chris