-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmergefiles.py
31 lines (23 loc) · 887 Bytes
/
mergefiles.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
import csv
if __name__ == '__main__':
filesToMerge = ['test_train_csv_files/strength0_mfcc_test.csv', 'test_train_csv_files/strength0_mfccplus_test.csv']
#create csv readers for each file
readers = [csv.reader(open(filename, 'rb'), delimiter =',') for filename in filesToMerge]
#create output file
outfile = 'test_train_csv_files/all_features_test.csv'
writer = csv.writer(open(outfile, 'wb'), delimiter = ',')
numRows = 0
for row in readers[0]:
numRows = numRows + 1
readers[0] = csv.reader(open(filesToMerge[0], 'rb'), delimiter =',')
numFiles = len(filesToMerge)
print readers
for i in xrange(numRows):
curr_row = []
for i in xrange(numFiles):
reader = readers[i]
if i == numFiles-1:
curr_row.extend(reader.next())
else:
curr_row.extend(reader.next()[0:-1])
writer.writerow(curr_row)