4 Module/script to calculate mean number of sightings of a given animal in a
5 given sightings csv file.
9 import matplotlib.mlab as ml
13 def get_sightings(filename, focusanimal):
16 tab = ml.csv2rec(filename)
18 # Standardize capitalization of focusanimal
19 focusanimal = focusanimal.capitalize()
21 # Find number of records and total count of animals seen
22 isfocus = (tab['animal'] == focusanimal)
23 totalrecs = np.sum(isfocus)
28 meancount = np.mean(tab['count'][isfocus])
30 # Return num of records and animals seen
31 return totalrecs, meancount
34 def get_sightings_loop(filename, focusanimal):
37 tab = ml.csv2rec(filename)
39 # Loop through all records, countings recs and animals
43 if rec['animal'] == focusanimal:
45 totalcount += rec['count']
47 meancount = totalcount/totalrecs
49 # Return num of records and animals seen
50 return totalrecs, meancount
52 if __name__ == '__main__':
54 filename = sys.argv[1]
55 focusanimal = sys.argv[2]
56 print get_sightings(filename, focusanimal)