''' Purpose: determine a rough estimate of the geocenter of the continental USA ''' # 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 dataset = url.get_dataset( USA_DATASET ) # determine webfile header and location data header = dataset[ 0 ] locations = dataset[ 1: ] # determine geocenter latitudes = [] longitudes = [] for row in locations: zipcode, town, state, latitude, longitude = row # split row into columns latitude = float( latitude ) # Take columns that are interesting and convert them into the right data type longitude = float( longitude ) latitudes.append( latitude ) # Accumulate the latitudes and longitudes longitudes.append( longitude ) latitudes = sorted( latitudes ) longitudes = sorted( longitudes ) num_of_locations = len( locations ) middle = num_of_locations // 2 mid_lat = latitudes[ middle ] mid_long = longitudes[ middle ] print( "mid_lat", mid_lat, "mid_long", mid_long ) first_lat = latitudes[ 0 ] last_lat = latitudes[ num_of_locations - 1 ] # index of the last thing in the list is (size of list) - 1 new_mid_lat = ( first_lat + last_lat ) / 2 first_long = longitudes[ 0 ] last_long = longitudes[ num_of_locations - 1 ] new_mid_long = ( first_long + last_long ) / 2 print( "new_mid_lat", new_mid_lat, "new_mid_long", new_mid_long ) # This was the right way to do it