My Pandas data frame has one million rows. I have to call a rest API call inside a function on each row and need to capture the response. Each rest call taking 2 sec of time on an average. But the following cases which I tried are very slow
Case 1: apply
def predict(x):
res = request("XYZ")
return res.json()
df['response_value'] = df.apply(lambda x:predict(x['request_filed']),axis=1)
Case 2: Vectorisation instead of apply
def predict(x):
l = []
for each in x
l.append(request("XYZ"))
return l
df['response_value'] = predict(df['request_filed']
Case 3: Paralleled apply
def predict(x):
res = request("XYZ")
return res.json()
df['response_value'] = df.parallel_apply(lambda x:predict(x['request_filed']),axis=1)
Is their any better way to speed up the process?