-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
36 lines (33 loc) · 1.13 KB
/
code.py
File metadata and controls
36 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 25 01:34:46 2024
@author: harpr
https://www.datacamp.com/tutorial/geocoding-for-data-scientists
"""
#%%
import pandas as pd
import geopy
l_cols= ['Name','Street Address','City','State','Zipcode']
df = pd.read_csv('D:/geocoding/museums list CAN.csv', encoding = "ISO-8859-1",usecols=l_cols)
#%%
df['Country'] = 'Canada'
l_cols_concat = ['Street Address','City','State','Zipcode','Country']
df['unique_address'] = df['Name'].str.cat(others=df[l_cols_concat], sep=',',na_rep='')
df.head()
#%%
address1 = df['unique_address'].iloc[0]
#%%
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="bainselly95@gmail.com")
location = geolocator.geocode(address1)
print(location)
#%%
l_cols_concat = ['City','State','Country']
df['unique_address_osm'] = df['Street Address'].str.cat(others=df[l_cols_concat], sep=',',na_rep='')
address1_osm = df['unique_address_osm'].iloc[0]
#%%
address1_osm = df['unique_address_osm'].iloc[0]
#%%
location = geolocator.geocode(address1_osm)
print('Latitude: '+str(location.latitude)+', Longitude: '+str(location.longitude))
#%%