How to Combine 2 Different Loops one is the name of the company the other the value? with python

Question:

Hello Everybody can somebody help me, I’m trying to combine the result of 2 different loops in one data frame, my code is below: I will show the output and an idea of how I would like it, in advance I appreciate your help:

enter image description here

This my actual output

enter image description here

But I want something like this:

enter image description here

Thank you Guys Or also if there’s any suggestion about my code or if I can make it simpler
I’m open to suggestions thank you all

Asked By: Mrc Rblr

||

Answers:

you could zip the 2 lists (im assuming lists or tuples are returned for soup.findall) together and iterated over it once, and extract the 2 elements at the same time so you can pass that new list into a dataframe

prices_list=[]
for span1,span2 in zip(soup.findall("div", attr = {"class":"quote-rate-logo"}),soup.findall("span", attr = {"class":"quote-rate"}):
    for img in span1:
        #your code here
        image_name = foo
    prices = span.text
    prices_list.append([image_name, prices])
df = pd.DataFrame(prices_list)
    
Answered By: Christian Trujillo