-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtripDataProject.py
More file actions
67 lines (55 loc) · 2.68 KB
/
tripDataProject.py
File metadata and controls
67 lines (55 loc) · 2.68 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import csv
#with open("/Users/JHuynh/Desktop/tripDataProject/Vietnam service data.csv", "r") as dataFile:
#dataFileReader = csv.reader(dataFile)
#dataList = [] #empty list here
#for row in dataFileReader:
#if len(row) != 0:
#dataList = dataList + [row]
#dataFile.close()
#print (dataList)
def averagePercentile(totalPercentile, totalNumberOfSubjects):
return totalPercentile/totalNumberOfSubjects
def analyzeData( dataFile ):
with open(dataFile, "r") as dataFile:
dataFileReader = csv.reader(dataFile)
maleCounter = 0
femaleCounter = 0
totalCounter = 0
totalWeight = 0
totalHeight = 0
totalFemaleWeight = 0
totalFemaleHeight = 0
totalMaleWeight = 0
totalMaleHeight = 0
for row in dataFileReader:
if row[3] == '1':
if row[2] == 'M':
maleCounter = maleCounter + 1
totalMaleWeight = totalMaleWeight + float(row[4])
totalMaleHeight = totalMaleHeight + float(row[5])
else:
femaleCounter = femaleCounter + 1
totalFemaleWeight = totalFemaleWeight + float(row[4])
totalFemaleHeight = totalFemaleHeight + float(row[5])
totalCounter = totalCounter + 1
totalWeight = totalWeight + float(row[4])
totalHeight = totalHeight + float(row[5])
avgMaleHeight = averagePercentile(totalMaleHeight, maleCounter)
avgMaleWeight = averagePercentile(totalMaleWeight, maleCounter)
avgFemaleHeight = averagePercentile(totalFemaleHeight, femaleCounter)
avgFemaleWeight = averagePercentile(totalFemaleWeight, femaleCounter)
avgHeight = averagePercentile(totalHeight, totalCounter)
avgWeight = averagePercentile(totalWeight, totalCounter)
print( "number of males: " + str(maleCounter) )
print( "number of females: " + str(femaleCounter) )
print( "total kids examined: " + str(totalCounter) )
print( "males average height percentile: " + str(avgMaleHeight) )
print( "males average weight percentile: " + str(avgMaleWeight) )
print( "females average height percentile: " + str(avgFemaleHeight) )
print( "females average weight percentile: " + str(avgFemaleWeight) )
print( "total average height percentile: " + str(avgHeight) )
print( "total average weight percentile: " + str(avgWeight) )
dataFile.close()
analyzeData("/Users/JHuynh/Desktop/tripDataProject/Vietnam service data 7:19:16.csv")
print('**********wheeee**********')
analyzeData("/Users/JHuynh/Desktop/tripDataProject/Vietnam service data 7:20:16.csv")