[英]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.