简体   繁体   中英

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

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?

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.

We can load arff data into python using scipy.

from scipy.io import arff

import pandas as pd

data = arff.loadarff('dataset.arff')

df = pd.DataFrame(data[0])

df.head()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM