Skip to content Skip to sidebar Skip to footer

Generator' Object Has No Attribute 'data', Problems Loading Some File With Scipy?

Im new with python and I'm triying to load .arff file with python this is what i tried: import arff , numpy as np file1 = open('/Users/user/Desktop/example.arff') dataset = arff.l

Solution 1:

There are two arff's that can be installed, you probably need to install liac-arff, you currently have arff installed which returns a generator from arff.load.

file1 = open('example.arff', "rb")
dataset = arff.load(file1)
print(dataset)
{u'attributes': [(u'width', u'NUMERIC'), (u'height', u'NUMERIC'), (u'color', [u'red', u'green', u'blue', u'yellow', u'black'])], u'relation': u'foo', u'description': u'', u'data': [[5.0, 3.25, u'blue'], [4.5, 3.75, u'green'], [3.0, 4.0, u'red']]}

For the arff you have installed don's pass a file object just load the file directly:

dataset = arff.load('eg.arff')
for row in dataset:
    x = row.color
    print(x)
blue
green
red

Solution 2:

The pypi page for arff shows how to use its load

https://pypi.python.org/pypi/arff/0.9

>>>import arff>>>for row in arff.load('example.arff'):...print(row.hair_color)...print(row[-1])...>>>print(list(arff.load('example.arff')))
[[Row(hair_color='blonde', age=17.2, patno=1),
 Row(hair_color='blue', age=27.2, patno=2),
 Row(hair_color='blue', age=18.2, patno=3)]

Since arff.load is a Python generator, it does not load the file immediately. Rather you have to call it 'iteratively', as in the:

for row in arff.load(...)

wrapping it in list() has the same effect - calling the load repeatedly until it is done.

Solution 3:

As of python 3 it seems like the list(arff.load('...')) method doesn't return attributes with the arff module (0.9) instead use Row._data (private but when it sticks, push):

for row in list(arff.load(fid)):
   print( row._data )

http://pydoc.net/Python/arff/0.9/arff/

Post a Comment for "Generator' Object Has No Attribute 'data', Problems Loading Some File With Scipy?"