-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.py
47 lines (31 loc) · 1.22 KB
/
func.py
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
37
38
39
40
41
42
43
44
45
46
47
from geopy.geocoders import Nominatim
import pandas as pd
import time
def generate_batch(name='', batch_size=1, testing=False):
geo_locator = Nominatim(user_agent='Phase_App')
batch = geo_locator.geocode(name, exactly_one=testing, limit=batch_size, addressdetails=True)
block = []
coords = []
for line in batch:
line_data = line.raw
line_coord = {'lat/lon': [line_data['lat'], line_data['lon']]}
address_data = line_data['address']
address_headers = list(line_data['address'].keys())
try:
address_data['name'] = address_data.pop(address_headers[0])
except KeyError:
print("error")
block.append(address_data)
coords.append(line_coord)
print(line_data)
address_frame = pd.DataFrame.from_records(block, index=None)
coord_frame = pd.DataFrame.from_records(coords)
result_frame = address_frame.join(coord_frame)
result_frame = result_frame.fillna('NaN')
time.sleep(20)
return result_frame
def load_biznames():
with open('Business_Names.txt', encoding='utf-8') as file:
biz_names = [line.strip() for line in file]
return biz_names
# df = pd.DataFrame.from_records(block,index=None)