Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate through Dataframe Rows in Loop [duplicate]

Tags:

python

pandas

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

My logic is as follows

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.
like image 784
Bronson77 Avatar asked Aug 12 '26 19:08

Bronson77


1 Answers

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

Simply use a for loop:

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
like image 119
Erfan Avatar answered Aug 14 '26 09:08

Erfan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!