【问题标题】:Reading multiple .csv files for training and testing in tensorflow读取多个 .csv 文件以在 tensorflow 中进行训练和测试
【发布时间】:2020-04-22 06:46:46
【问题描述】:

我只是一个使用 tensorflow 的初学者。我在 python 中编写了一个代码,它读取单个 .csv 文件并将其拆分为训练和测试。我是这样做的:

diode_df=pd.read_csv("./fun.csv", sep=",",names=['voltage','current'])

但是现在,我有大约 1000 个 .csv 文件,每个文件都有特征和标签列。我想读取 1000 个文件中的 900 个文件用于训练,其余 100 个文件用于测试。任何人都可以帮助如何做到这一点?

【问题讨论】:

    标签: python csv tensorflow


    【解决方案1】:
    import os
    import pandas as pd
    
    files = os.path.listdir('./')
    train = pd.DataFrame()
    test = pd.DataFrame()
    for file in files:
      df = pd.read_csv(file, sep=",",names=['voltage','current'])
      if i < 900:
        train.append(df)
      else:
         test.append(df)
    

    【讨论】:

    • 这破坏了边界。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-22
    • 2017-09-27
    • 2017-02-25
    • 1970-01-01
    • 2020-01-30
    • 2017-11-09
    • 2017-01-15
    相关资源
    最近更新 更多