Advertisement
mayankjoin3

Column Wise Split CC

Oct 17th, 2022
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Oct 15 23:01:33 2022
  4.  
  5. @author: Sanjit
  6. """
  7.  
  8. import os
  9. import pandas as pd
  10.  
  11. inDF = pd.read_csv('input.csv')
  12. # nTrain = 5                   # for n number
  13. nTrain = int(len(inDF)*0.7)    # for 70%
  14.  
  15. corrSer = inDF.corr().iloc[:,-1].abs().sort_values(ascending=False)
  16. resDF = inDF[corrSer.index[1:].append(corrSer.index[:1])]
  17.  
  18. if(not os.path.exists('output')):
  19.     os.mkdir('output')
  20.  
  21. for i in range(resDF.shape[1]):
  22.     for j in range(i):
  23.         if(not os.path.exists('output/input Group%s'%i)):
  24.             os.mkdir('output/input Group%s'%i)
  25.         resDF[resDF.columns[:j+1].append(resDF.columns[-1:])][:nTrain].to_csv('output/input Group%s/trainGroup%s.csv'%(i,i), index=False)
  26.         resDF[resDF.columns[:j+1].append(resDF.columns[-1:])][nTrain:].to_csv('output/input Group%s/testGroup%s.csv'%(i,i), index=False)
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement