循环遍历数据帧行 [英] Iterate through Dataframe Rows in Loop

查看:97
本文介绍了循环遍历数据帧行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据框中包含链接行.

I have rows of links contained in a dataframe.

df = pd.DataFrame()

我需要一次遍历数据帧中的链接行,以便可以分别在每个链接上执行硒任务.它应该循环遍历这些行,直到数据帧中没有更多行为止.

I need to iterate over the rows of links in the dataframe one at a time so I can perform selenium tasks on each link separately. It should iterate over these rows in a loop until there are no more rows in the dataframe.

     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循环即可.

In this case you dont need iterrows(), just use a for loop.

只需使用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

这篇关于循环遍历数据帧行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆