1. 程式人生 > >python 利用pandas將arff檔案轉csv檔案

python 利用pandas將arff檔案轉csv檔案

直接貼程式碼啦:

#coding=utf-8
import pandas as pd

def arff_to_csv(fpath):
    #讀取arff資料
    if fpath.find('.arff') <0:
        print('the file is nott .arff file')
        return
    f = open(fpath)
    lines = f.readlines()
    content = []
    for l in lines:
        content.append(l)
    datas = []
    for
c in content: cs = c.split(',') datas.append(cs) #將資料存入csv檔案中 df = pd.DataFrame(data=datas,index=None,columns=None) filename = fpath[:fpath.find('.arff')] + '.csv' df.to_csv(filename,index=None)