Created
April 24, 2020 10:29
-
-
Save ShayanRiyaz/5806adc4221fcc298650ae8d8b696f8f 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
# define the data frame columns | |
column_names = ['Neighbourhood', 'Latitude', 'Longitude'] | |
# instantiate the data frame | |
nhoods = pd.DataFrame(columns=column_names) | |
geolocator = Nominatim(user_agent="la_explorer",timeout=5) | |
for i in range(0,len(df)): | |
address = df.Neighbourhood[i]+', Los Angeles' | |
location = geolocator.geocode(address) | |
if location == None: | |
latitude = 0 | |
longitude = 0 | |
else: | |
latitude = location.latitude | |
longitude = location.longitude | |
nhoods = nhoods.append({'Neighbourhood': df.Neighbourhood[i], | |
'Latitude': latitude, | |
'Longitude': longitude}, ignore_index=True) | |
nhoods['Latitude']=nhoods['Latitude'].astype(float) | |
nhoods['Longitude']=nhoods['Longitude'].astype(float) | |
nhoods=nhoods[(nhoods.Latitude>33.5) & (nhoods.Latitude<34.4) & (nhoods.Longitude<-118)] | |
nhoods.reset_index(inplace=True,drop=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment