How to convert the arff object loaded from a .arff file into a dataframe format?
Asked Answered
F

2

11

I was able to load the .arff file using the following commands. But I was not able to extract the data from the object and convert the object into a dataframe format. I need this to do apply machine learning algorithms on this dataframe.

Command:-

import arff
dataset = pd.DataFrame(arff.load(open('Training Dataset.arff')))
print(dataset)

Please help me to convert the data from here into a dataframe.

Foreordination answered 25/9, 2017 at 8:54 Comment(0)
S
18
import numpy as np
import pandas as pd
from scipy.io.arff import loadarff 

raw_data = loadarff('Training Dataset.arff')
df_data = pd.DataFrame(raw_data[0])

Try this. Hope it helps

Stedmann answered 18/11, 2017 at 14:2 Comment(0)
H
0
from scipy.io.arff import loadarff
import pandas as pd

data = loadarff('Training Dataset.arff')
df = pd.DataFrame(data[0])

Similar to answer above, but no need to import numpy

Headband answered 6/2, 2021 at 17:56 Comment(1)
The import statement is incorrect. This will not run b/c in line 4 arff is not defined.Shabby

© 2022 - 2024 — McMap. All rights reserved.