【问题标题】:getting back feature extraction result in a csv在 csv 中取回特征提取结果
【发布时间】:2018-12-17 13:54:25
【问题描述】:

我有一个 csv 数据集,并应用了小波、峰度等特征提取,以便以后进行机器学习。我是 python 和机器学习的新手,所以无法理解如何取回特征提取的 csv 文件。

Dataset

我无法取回特征提取的 csv 文件。我该怎么办?

这是我写的代码。 我希望我得到 features.csv 结果,但它没有写入它。

path = r"C:\Users\DELL PC\Desktop\Msc Project\MSc project\dataset"
for file in os.listdir(path):
    print(file)

lowfiles = files(os.path.join(path, r"Training data\LOW"))
highfiles = files(os.path.join(path, r"Training data\HIGH"))

mypath = 'Training-Data/'
csvfile = "Features/features.csv"

with open(csvfile, "a") as output:
    writer = csv.writer(output, lineterminator='\n')
    writer.writerow(names) 

    subfolder =  files[counter][1]
    tag = files[counter][1] 
    data_path = mypath + subfolder +'/'+files[counter][0]

【问题讨论】:

  • 欢迎来到 SO;请检查如何正确格式化您的代码块(我们这次为您做了)...

标签: python-3.x machine-learning feature-extraction training-data


【解决方案1】:

看看pandas 模块。它提供了大量的 I/O 功能、强大的数据处理等等。

从磁盘加载 CSV 文件非常简单:

import pandas as pd
df = pd.read_csv('path/to/infile.csv')

其中dfDataFrame,这是pandas 的主要数据结构。

DataFrame 作为 CSV 文件写入磁盘也只需一行:

df.to_csv('outfile.csv')

这个link provides documentation to pandas I/O

【讨论】:

    猜你喜欢
    • 2020-07-18
    • 2011-07-25
    • 2012-02-16
    • 1970-01-01
    • 2019-05-26
    • 2021-10-23
    • 2014-01-03
    • 2014-05-13
    • 2017-09-06
    相关资源
    最近更新 更多