-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompositeData.py
54 lines (43 loc) · 1.52 KB
/
compositeData.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
# Creating a car inventory data (CSV -> car_fleet.csv)
# Creating a car inventory program
# Defining the dictionary
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["milegae"] = 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("-----")