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.
[]
conv_stores1 = yelp_api.search_query(categories= 'convenience stores', latitude=30.62779075491679, longitude=-96.33484825223623, limit=50)
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.
CodePudding user response:
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)