![](/img/trans.png)
[英]Python Pandas - Send one post url request per dataframe row with custom delay between them
[英]Send post request with data in every row of dataframe in pandas
我有一個 pandas dataframe 如圖所示:
header
data1
data2
data3
data4
我必須使用此 dataframe 的每一行發送一個發布請求,作為與發布請求一起發送的數據。 並將每個響應記錄在與該行中的請求對應的新列中。 如何在不遍歷 dataframe 的情況下一次完成所有操作?
您可以創建一個 function ,它將一些數據作為輸入,並使用數據進行發布請求並返回響應。 Then use pandas.DataFrame.apply function to map all the values to the function.
def Post_Function(data):
url = "insert your URL here"
response = requests.post(url, data = data)
return response
然后你可以調用上面的 function 像(假設你的 dataframe 被命名為“df”)
df["Response"] = df.apply(Post_Function, axis = 1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.