-
-
Save rebecca-sich/1c422acc1b222b8a04fcd3cfae79bc18 to your computer and use it in GitHub Desktop.
Distance between geographic centers of all US states
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
state | latitude | longitude | |
---|---|---|---|
Alabama | 32.7794 | -86.8287 | |
Alaska | 64.0685 | -152.2782 | |
Arizona | 34.2744 | -111.6602 | |
Arkansas | 34.8938 | -92.4426 | |
California | 37.1841 | -119.4696 | |
Colorado | 38.9972 | -105.5478 | |
Connecticut | 41.6219 | -72.7273 | |
Delaware | 38.9896 | -75.5050 | |
District of Columbia | 38.9101 | -77.0147 | |
Florida | 28.6305 | -82.4497 | |
Georgia | 32.6415 | -83.4426 | |
Hawaii | 20.2927 | -156.3737 | |
Idaho | 44.3509 | -114.6130 | |
Illinois | 40.0417 | -89.1965 | |
Indiana | 39.8942 | -86.2816 | |
Iowa | 42.0751 | -93.4960 | |
Kansas | 38.4937 | -98.3804 | |
Kentucky | 37.5347 | -85.3021 | |
Louisiana | 31.0689 | -91.9968 | |
Maine | 45.3695 | -69.2428 | |
Maryland | 39.0550 | -76.7909 | |
Massachusetts | 42.2596 | -71.8083 | |
Michigan | 44.3467 | -85.4102 | |
Minnesota | 46.2807 | -94.3053 | |
Mississippi | 32.7364 | -89.6678 | |
Missouri | 38.3566 | -92.4580 | |
Montana | 47.0527 | -109.6333 | |
Nebraska | 41.5378 | -99.7951 | |
Nevada | 39.3289 | -116.6312 | |
New Hampshire | 43.6805 | -71.5811 | |
New Jersey | 40.1907 | -74.6728 | |
New Mexico | 34.4071 | -106.1126 | |
New York | 42.9538 | -75.5268 | |
North Carolina | 35.5557 | -79.3877 | |
North Dakota | 47.4501 | -100.4659 | |
Ohio | 40.2862 | -82.7937 | |
Oklahoma | 35.5889 | -97.4943 | |
Oregon | 43.9336 | -120.5583 | |
Pennsylvania | 40.8781 | -77.7996 | |
Rhode Island | 41.6762 | -71.5562 | |
South Carolina | 33.9169 | -80.8964 | |
South Dakota | 44.4443 | -100.2263 | |
Tennessee | 35.8580 | -86.3505 | |
Texas | 31.4757 | -99.3312 | |
Utah | 39.3055 | -111.6703 | |
Vermont | 44.0687 | -72.6658 | |
Virginia | 37.5215 | -78.8537 | |
Washington | 47.3826 | -120.4472 | |
West Virginia | 38.6409 | -80.6227 | |
Wisconsin | 44.6243 | -89.9941 | |
Wyoming | 42.9957 | -107.5512 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from geopy.distance import distance | |
# load csv with states' data. | |
# this csv is included in this gist. | |
# Data taken from https://en.wikipedia.org/wiki/List_of_geographic_centers_of_the_United_States#Updated_list_of_geographic_centers | |
# Coordinates correspond to Updated geographic centers of the states of the United States and Washington, DC | |
statesDF = pd.read_csv('states.csv'); | |
# create distances dataframe | |
distancesDF = pd.DataFrame(columns=["state1", "state2", "distance"]) | |
# Line 22 can be modified to calculate whichever distance is preferred. | |
for state1, lat1, lon1 in zip(statesDF.state, statesDF.latitude, statesDF.longitude): | |
for state2, lat2, lon2 in zip(statesDF.state, statesDF.latitude, statesDF.longitude): | |
new_data= pd.DataFrame({ | |
"state1": [state1], | |
"state2": [state2], | |
"distance": [distance((lat1, lon1), (lat2, lon2)).miles] | |
}); | |
distancesDF = pd.concat([distancesDF, new_data], ignore_index=True) | |
distancesDF.to_csv('state_distances.csv', index=False); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment