-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfile_upload.py
More file actions
26 lines (19 loc) · 841 Bytes
/
file_upload.py
File metadata and controls
26 lines (19 loc) · 841 Bytes
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
import csv
def preprocess_csv(file_name):
csvHeader = [] # Stores header of the csv File
csvRows = [] # Stores Rest of the rows - values
# Read CSV file
csvFileObj = open(file_name) # reads csv file
readerObj = csv.reader(csvFileObj) # creates a reader object
# Separate header row and other rows in different lists
for row in readerObj:
if readerObj.line_num == 1: # line #1 corresponds to header
csvHeader = row # store header in a list csvHeader
else:
csvRows.append(row) # stores the values in list csvRows
csvFileObj.close()
csvList = [] #stores list of column vectors([x1],[x2],[x3]...,[xn],[y])
# Create list of column vectors
for i in range(len(csvHeader)):
csvList.append([row[i] for row in csvRows])
return csvHeader, csvList