Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a loop for a search query using set coordinates from a data frame, while creating a new data frame for each search result?

I a really new to programming and can’t seem to find a way to create a loop that matches what I am looking for.

[dataframe with coordinates I want to loop]

conv_stores1 = yelp_api.search_query(categories= ‘convenience stores’, latitude=30.62779075491679, longitude=-96.33484825223623, limit=50)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this is the code I am trying to loop over.

conv_stores1 = yelp_api.search_query(categories= ‘convenience stores’, latitude=[0], longitude=[0], limit=50)

this is what I first attempted but it was not using the coordinates from my data frame so I wrote it manually. For the actaul loop I am not sure hopw to write it.

I apolagize if I am missing details or messed to in a super obvious way, thank you for your time and helping out.

>Solution :

If I understand you correctly, to put it simply, you need something like the following;
Assuming your dataframe is called "df":

for i in range(df.shape[0]):
    conv_stores = yelp_api.search_query(categories= 'convenience stores', df['latitude'].iloc[i], df['longitude'].iloc[i], limit=50)
    print (conv_stores)

And a better version would be using a lambda function and adding the results as a new column to your original dataframe;

df['conv_stores'] = df.apply(lambda x: yelp_api.search_query(categories= 'convenience stores', x['latitude'], x['longitude'], limit=50), axis=1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading