Skip to content

how to extract for a list of lat/long #132

@systemsGit

Description

@systemsGit

I have a data frame that consist of Store ID and its lat/lon. I want to iterate through that dataframe and for each store ID find key places nearby using the google api.

for example input:

Store-ID LAT LON
1 1.222 2.222
2 2.334 4.555
3 5.433 7.2343
Output should be (in a new dataframe):

Store-ID Places found ......
1 school
1 cafe
1 cinema
1 bookstore
.
.
.
2 toy store
2 KFC
and so on ..........

so far I have tried the following but fail to create a new data frame that would match the output format I mentioned above

map_client = googlemaps.Client(API_KEY)
theta = 0
search_string =['school','store','bank','restaurant','clothing_store','health','mosque','hospital','car_dealer','finance','electronics_store','university','home_goods_store']
distance = km_to_meters(0.1)

sc = []
business_list = []
import time
import math
for i, row in POI_copy.iterrows():
print(i, row[0], row[1], row[2])
for string in search_string:

coordinates = (row[1], row[2])
response = map_client.places_nearby(
location = coordinates,
keyword = string,
radius = distance
    )
business_list.extend(response.get('results'))
print(f'we have found a place and we are appending for store code{row[0]}')
sc.append(str(row[0]))
next_page_token = response.get('next_page_token')

while next_page_token:
    time.sleep(2)
    response = map_client.places_nearby(
    location= coordinates,
    keyword=string,
    radius=distance,
    page_token=next_page_token)
    business_list.extend(response.get('results'))
    next_page_token = response.get('next_page_token')
    print(f'we have found a place and we are appending for store code{row[0]}')
    sc.append(str(row[0]))

I also want to know if we could extract more info for each place like rating, timings, busiest hour of the day, busiest day of the week and append to the dataframe

https://stackoverflow.com/q/69744146/16447945

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions