-
Notifications
You must be signed in to change notification settings - Fork 0
/
composite-data.py
45 lines (40 loc) · 1.43 KB
/
composite-data.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
import csv
import copy
myVehicle = {
"vin" : "<empty>",
"make" : "<empty>" ,
"model" : "<empty>" ,
"year" : 0,
"range" : 0,
"topSpeed" : 0,
"zeroSixty" : 0.0,
"mileage" : 0
}
for key, value in myVehicle.items():
print("{} : {}".format(key,value))
myInventoryList = []
with open('car_fleet.csv') as csvFile:
csvReader = csv.reader(csvFile, delimiter=',')
lineCount = 0
for row in csvReader:
if lineCount == 0:
print(f'Column names are: {", ".join(row)}')
lineCount += 1
else:
print(f'vin: {row[0]} make: {row[1]}, model: {row[2]}, year: {row[3]}, range: {row[4]}, topSpeed: {row[5]}, zeroSixty: {row[6]}, mileage: {row[7]}')
currentVehicle = copy.deepcopy(myVehicle)
currentVehicle["vin"] = row[0]
currentVehicle["make"] = row[1]
currentVehicle["model"] = row[2]
currentVehicle["year"] = row[3]
currentVehicle["range"] = row[4]
currentVehicle["topSpeed"] = row[5]
currentVehicle["zeroSixty"] = row[6]
currentVehicle["mileage"] = row[7]
myInventoryList.append(currentVehicle)
lineCount += 1
print(f'Processed {lineCount} lines.')
for myCarProperties in myInventoryList:
for key, value in myCarProperties.items():
print("{} : {}".format(key,value))
print("-----")