Created
April 24, 2020 10:34
-
-
Save ShayanRiyaz/b695b6cc10e2b61b3629caa1a76c5516 to your computer and use it in GitHub Desktop.
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
filter2_nhoods = filter2_nhoods.reindex( columns = filter2_nhoods.columns.tolist() + ['Distance from LA center (in km)']) #this way to avoid warnings | |
from math import radians, sin, cos, acos | |
slat = radians(34.0536909) #LA center Latitude obtained earlier | |
slon = radians(-118.2427666) #LA center Longitude obtained earlier | |
for n in range(0,len(filter2_nhoods)): | |
elat = radians(filter2_nhoods.iloc[n,1]) | |
elon = radians(filter2_nhoods.iloc[n,2]) | |
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon)) | |
filter2_nhoods.loc[n,'Distance from LA center (in km)']=dist | |
filter2_nhoods.sort_values(by='Distance from LA center (in km)',inplace=True) | |
filter2_nhoods.reset_index(drop=True,inplace=True) | |
filter2_nhoods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment