gpt4 book ai didi

python - 在循环中迭代数据帧行

转载 作者:行者123 更新时间:2023-12-01 01:07:36 24 4
gpt4 key购买 nike

我的数据框中包含多行链接。

df = pd.DataFrame()

我需要一次迭代数据帧中的链接行,以便我可以分别对每个链接执行 selenium 任务。它应该循环遍历这些行,直到数据框中不再有行。

     links
0 http://linkone
0 http://linktwo
0 http://linkthree

我的逻辑如下

Loop
Get http://linkone in first row of dataframe
Use selenium to perform tasks, such as driver.get(http://linkone)
Gather data from HTML from http://linkone

Continue loop and get row 2, row 3, etc.

最佳答案

在这种情况下,您不需要 iterrows(),只需使用 for 循环即可。

只需使用 for 循环:

for link in df.links:
print(link)
print('do something with selenium')

http://linkone
do something with selenium
http://linktwo
do something with selenium
http://linkthree
do something with selenium

关于python - 在循环中迭代数据帧行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55192162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com