''' Purpose: determine a rough estimate of the geocenter of the continental USA ''' # get access to CS 1112 web-based data support import url # name the location of the data repository CSV_WEB_FOLDER = 'http://www.cs.virginia.edu/~cs1112/datasets/csv/' USA_DATASET = CSV_WEB_FOLDER + 'continental-usa.csv' # get the dataset of interest dataset = url.get_and_parse_dataset( USA_DATASET ) # determine webfile header and location data header = dataset[ 0 ] locations = dataset[ 1: ] num_of_locations = len( locations ) # determine geocenter # start by getting the lists of latitudes and longitudes from the data set latitudes = [] longitudes = [] for row in locations: zipcode, town, state, latitude, longitude = row latitudes.append( latitude ) longitudes.append( longitude ) # now sort the lists latitudes = sorted( latitudes ) longitudes = sorted( longitudes ) # find the median latitude and longitude mid_index = num_of_locations // 2 median_latitude = latitudes[ mid_index ] median_longitude = longitudes[ mid_index ] # use them to get the median median = ( median_latitude, median_longitude ) # print result print( median )