-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrain_and_test_creation.py
81 lines (56 loc) · 1.67 KB
/
train_and_test_creation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
"""Train and test creation.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1wFbLhnmmsLBB5VKsvbZ76M5XrfBBNVBy
"""
#CSV File Processing
import csv
import glob
from pathlib import Path
import os
#Data Processing
import pandas as pd #Data Processing
from google.colab import drive
drive.mount('/content/drive')
# setting work directory
wd = 'drive/Shared drives/UptakeDS/Data'
os.chdir(wd)
# Making test files
path = 'Data 2014-2016/' # use your path
count = 0
for y in [2014]:
for j in range(7,13):
if len(str(j-3)) == 1:
i = '0'+str(j-3)
else:
i = str(j-3)
file = "Copy of "+str(y)+"-"+i+"-*.csv"
all_files = glob.glob(os.path.join(path, file))
df_from_each_file = (pd.read_csv(f) for f in all_files)
concatenated_df = pd.concat(df_from_each_file, ignore_index=True)
concatenated_df[:].to_csv('test_'+str(count)+'.csv')
count = count +1
# Making train files
path = 'Data 2014-2016/' # use your path
count = 0
for y in [2014]:
for j in range(7,13):
a = []
for k in range(1,7):
if len(str(j-k)) == 1:
b = '0'+str(j-k)
else:
b = str(j-k)
a.append(b)
print(a)
frames =[]
for l in range(len(a)):
file = "Copy of "+str(y)+"-"+a[l]+"-*.csv"
read1 = glob.glob(os.path.join(path, file))
df_from_each_file = (pd.read_csv(f) for f in read1)
concatenated_df = pd.concat(df_from_each_file, ignore_index=True)
frames.append(concatenated_df)
result = pd.concat(frames)
result[:].to_csv('train_'+str(count)+'.csv')
count = count +1