''' Purpose: determine a rough estimate of the geocenter of the continental USA method(s): compute avg lat and long compute avg between min and max lat/long take a random sample and find the avg find farthest point in all 4 directions and avg ''' # get access to web-based data support import url # specify dataset web location CSV_WEB_FOLDER = 'http://www.cs.virginia.edu/~cs1112/datasets/csv/' USA_DATASET = CSV_WEB_FOLDER + 'continental-usa.csv' # get the dataset of interest using get_dataset() from url module dataset = url.get_dataset( USA_DATASET ) # determine webfile header and location data header = dataset[0] #first row locations = dataset[1:] #everything else #background # min_value = min(locations) #the above line won't work because location is a list of lists # determine geocenter sum_lat = 0 sum_long = 0 list_lat = [] list_long = [] for location in locations: #we are accessing rows here latitude = location[3] longitude = location[4] # sum_lat = sum_lat + latitude # sum_long = sum_long + longitude list_lat.append(latitude) list_long.append(longitude) #how do we use our accumulators? sum_lat = sum(list_lat) sum_long = sum(list_long) #lines 43-44 do the same as lines 37-38 #how do we get avg lat and long? avg_lat = sum_lat / len(list_lat) avg_long = sum_long / len(list_long) print(avg_lat, avg_long) #here's our first guess #38.52071282671683, -90.43203752861102 # this was in St.Louis, so not quite #attempt #2 min_lat = min(list_lat) max_lat = max(list_lat) min_long = min(list_long) max_long = max(list_long) mid_lat = ( max_lat + min_lat ) / 2 mid_long = ( max_long + min_long ) / 2 print(mid_lat, mid_long)