简体   繁体   English

如何将从 .arff 文件加载的 arff 对象转换为数据帧格式?

[英]How to convert the arff object loaded from a .arff file into a dataframe format?

I was able to load the .arff file using the following commands.我能够使用以下命令加载 .arff 文件。 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.请帮我将这里的数据转换为数据框。

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希望它有帮助

from scipy.io.arff import loadarff
import pandas as pd

data = arff.loadarff('breast-cancer.arff')
df = pd.DataFrame(data[0])

Similar to answer above, but no need to import numpy类似于上面的答案,但不需要导入 numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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