repl.it
@markpooley/

Python Week 2

Python 2.7

No description

fork
loading
Files
  • main.py
  • name_locations.csv
main.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
import csv

#Geographic Bounding box of North America(ish)
top = 72.471968 # north lat
left = -168.222656 # west long
right = -47.988281 # east long
bottom =  12.801088 # south lat

#empty list that we will append names to that are located inside the using
people_NA = []

#using the "with" syntax we only open the csv file for as long as we need to
#The name of the csv has to be in quotes, and we open it in a read only state "r"
#using the "as" is assigning the open file to a variable, in this case f
with open("name_locations.csv","r" ) as f:
  
  #create an object that reads the data in
  reader = csv.reader(f)
  next(reader, None) #we want to skip the header row, this little bit does that.
  
  #now we will iterate through the rows
  for row in reader:
    #think of the row as a list, where we can access certain elements of interest using the bracket and
    #index notation we've used in the past
    

    #in this case we want lat and lon, so we will create a variable
    #everything will be read in as a string, so we want to convert it 
    #to a decimal
    lat #access the index of the row where the lat is and convert it to float
    lon #access the index of the row where the lon is and convert it to float
     
    #lets evaulate if this location is within the continental united states using some comparisons
    # and conditional statmements
    
    #create a chained set of comparison evaluators to check 
    #chain comparisons. You're looking for a lat that is between the top and bottom
    # and a lon that is between the left and right (or right and left....)
    if .....:
      
      name = (tuple of data to append)
      
      

#You should get a list of 7 people and locations...
print people_NA, len(people_NA)