vendredi 26 juillet 2019

Stuck in an if statement in a while loop. How do i exit?

i wrote the following code to iteratively build a matrix depending on the conditions met. But i'm stuck in the 2nd if statement. for some reason it doesnt move to else and prints the contents of my print statements over and over, infinitely.

vi= df['GroupId'][0]
G_df= pd.DataFrame(index=np.arange(0, v), columns=['j', 'vi']) 
G_df['j'][0] = 0
G_df['vi'][0] = 0
j=0
i=0
old_tweet_id=1
new_tweet_id=1
value= df['TFIDF_score'][0]

while(i<u):
    old_tweet_id=new_tweet_id
    while (old_tweet_id == new_tweet_id):
        if (j < v):
            new_js= [G_df.loc[G_df['vi'] == vi, 'j'].item()] 
            if new_js != 0:
                print('new_js',new_js)
                new_j= int(''.join(str(x) for x in new_js))
                print('new_j', new_j)
                B[i][new_j] = value         
                print('matrix', B)                
            else: 
                G_df.loc[-1]=[j,vi]
                B[i][j]=value
                vi = vi +1
                j=j+1
            if (j>=v):
                old_tweet_id =  u +10
            else:
                cc = df['tweet_id'][j:j + 1]
                dd = df['TFIDF_score'][j:j + 1]
                value = dd[j]
                new_tweet_id = cc[j]

    i = i + 1

I tried using break and also tried to empty the new_js and new_j variables just before the else line but that didn't work either. I'm sure I'm missing something but I can't place my finger on it.

Aucun commentaire:

Enregistrer un commentaire