zoukankan      html  css  js  c++  java
  • pandas(五):pandas对CSV合并多个文件,分割训练集测试集

    一、pandas对CSV合并多个文件,分割训练集测试集

    def all_data(self):
        df1 = pd.read_csv("data/POI/negtive.csv")
        df2 = pd.read_csv("data/POI/positive.csv")
        df = pd.concat([df1,df2],ignore_index=True)
        df.to_csv("data/POI/all.csv",index=False,sep=',')
    def split(self):
        df = pd.read_csv('data/POI/all.csv')
        df = df.sample(frac=1.0)
        cut_idx = int(round(0.2 * df.shape[0]))
        df_test, df_train = df.iloc[:cut_idx], df.iloc[cut_idx:]
        df_test.to_csv("data/POI/test.csv",index=False,sep=',')
        df_train.to_csv("data/POI/train.csv", index=False, sep=',')
  • 相关阅读:
    such用法
    divorce用法
    towel用法
    go for用法
    catch on用法
    incredibly用法
    mess用法
    dentist用法
    steer clear of用法
    incredible
  • 原文地址:https://www.cnblogs.com/zhangxianrong/p/14870249.html
Copyright © 2011-2022 走看看