10

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.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Thomas John
  • 101
  • 1
  • 1
  • 5

2 Answers2

17
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

Sagar Dawda
  • 1,126
  • 9
  • 17
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

Peej1226
  • 132
  • 12
Adilius
  • 308
  • 2
  • 10
  • The import statement is incorrect. This will not run b/c in line 4 `arff` is not defined. – Devon Feb 05 '22 at 21:57