''' 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 #determine number of locations nbr_locations = len(locations) #determine the column number of zipcodes, latitudes, and longitudes zip_index = header.index( 'Zipcode' ) lat_index = header.index( 'Latitude' ) long_index = header.index( 'Longitude' ) #print( zip_index, lat_index, long_index ) # accumulate a list of all zipcodes, then latitudes, and then longitudes zips = [] lats = [] longs = [] for row in locations: zipcode = row[ zip_index ] latitude = row[ lat_index ] longitude = row[ long_index ] zips.append( zipcode ) lats.append( latitude ) longs.append( longitude ) #print ( 'zips:', zips[0:10] ) #print ( 'lats:', lats[0:10] ) #print( 'longs:', longs[0:10] ) # sort lists from smallest to largest zips = sorted( zips ) lats = sorted( lats ) longs = sorted( longs ) #print ( 'sorted zips:', zips[0:10] ) #print ( 'sorted lats:', lats[0:10] ) #print( 'sorted longs:', longs[0:10] ) # get min and max entries of the zips, lats, and longs min_zip = min(zips) min_lat = min(lats) min_long = min(longs) max_zip = max(zips) max_lat = max(lats) max_long = max(longs) # get median row median_index = nbr_locations // 2 median_zip = zips[ median_index ] median_lat = lats[ median_index ] median_long = longs[ median_index ] ave_min_max_zip = ( min_zip + max_zip ) // 2 ave_min_max_lat = ( min_lat + max_lat ) / 2.0 ave_min_max_long = ( min_long + max_long ) / 2.0 print( median_lat, median_long ) print( ave_min_max_zip ) print ( ave_min_max_lat, ave_min_max_long ) #get the sum of the lists after class #get average zipcode, latitude, longitude