-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveCSVheader.py
More file actions
25 lines (23 loc) · 1 KB
/
removeCSVheader.py
File metadata and controls
25 lines (23 loc) · 1 KB
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
#! python3
# removeCsvHeader.py - Removes the header from all CSV files in the current working directory.
import csv, os
os.makedirs('headerRemoved', exist_ok=True)
# Loop through every file in the current working directory.
for csvFilename in os.listdir('removeCSVheader'):
if not csvFilename.endswith('.csv'):
continue # skip non-csv files
else:
print('Removing header from ' + csvFilename + '...')
# TODO: Read the CSV file in (skipping first row).
csvFileObj = open(os.path.join('removeCSVheader', csvFilename))
csvFileObj1 = open(os.path.join('headerRemoved', csvFilename), 'w', newline='')
readerObj = csv.reader(csvFileObj)
csvWriter = csv.writer(csvFileObj1)
for row in readerObj:
if readerObj.line_num == 1:
continue # skip first row
else:
# TODO: Write out the CSV file.
csvWriter.writerow(row)
csvFileObj1.close()
csvFileObj.close()