Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write in ARFF file using LIAC-ARFF package in Python?

Tags:

python

arff

I want to load an ARFF file in python, then change some values of it and then save changes to file. I'm using LIAC-ARFF package (https://pypi.python.org/pypi/liac-arff). I loaded ARFF file with following lines of code:

import arff
data = arff.load(open(FILE_NAME, 'rb'))

After manipulating some values inside data, i want to write data to another ARFF file. Any solution?

like image 666
SuB Avatar asked Jul 02 '26 02:07

SuB


1 Answers

Use the following code:

import arff
data = arff.load(open(FILE_NAME, 'rb'))
f = open(outputfilename, 'wb')
arff.dump(data, f)
f.close()

In the LICA-ARFF description you see dump method which serializes to a the file, but it's wrong. It just write object as text file. Serialize means save whole the object, so the output file is binary not a text file.

like image 66
Jason007 Avatar answered Jul 04 '26 15:07

Jason007