Using conditional while loop until getting all API requests a result python

479 Views Asked by At

I am using pandarallel and requests to get results from a website but its responses to my API doesn't cover my whole request. So I want to do a while loop that takes unanswered rows nder to_doDf and sends requests to API for to_doDf while deleting rows from to_doDf and as I get responses from API. The basic logic is that while there are empty rows under results columns unless length of it is zero send a request to API until it receives an answer. But I can't write the code to delete the rows of answered API's.

doneDf = pd.DataFrame()
to_doDf = macmapDf_concat[macmapDf_concat['results'].isna()]
while len(to_doDf) != 0:
  doneDf['results'] = to_doDf.parallel_apply(lambda x: 
requests.get(f'https://www.macmap.org/api/results/customduties?reporter= 
{x["destination"]}&partner={x["source"]}&product={x["hs10"]}').json(), 
axis=1)
doneDf
0

There are 0 best solutions below