0

I have an excel file which contains two columns, column[0]= keyword and column1 = "urls" and each keyword has 10 urls. I am using this code to find if two or more keywords have urls in common and then printing those common urls along with only those keywords, which have urls in common. The codes takes the first url in the column and then checks if there is any other url which matches the first url and if it does then it prints those urls along with their respective keyword.

The problem is, its only going through the file once and giving me the results for only the first url in the column and not running again for the second url and so on... what do i do that will make the entire code run again for the 2nd url and then 3rd and so on....

And also how do i group each result seperately??

I would really appreciate if someone could help. Thanks!

here is my code

import pandas as pd
import pandas as pd

data = pd.read_excel("editing_cluster.xlsx", usecols = ["keyword","urls"] )
data
results = dict(), a=0, i=0

while a < len(data):

    while i < len(data):
        if data.loc[a]["urls"]==data.loc[i]["urls"]:
            results = [data.loc[i]["urls"],data.loc[i]["keyword"]]
            pprint(results)

        i+=1 
    a+=1

Output:

Screen shot of the code's output

1 Answer 1

1

You should initialize i=0 every time you you get into the second while loop. Your i get set to len(data) from first looping the second while loop and then never get in the second while loop again.

while a < len(data):
i=0
Sign up to request clarification or add additional context in comments.

1 Comment

I did this and it gave me all the urls after giving me the results only for just one url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.