I want to optimize 'double for loop' in python (like vlookup function)

Viewed 26

I make a 'double for loop' below. But I try to optimize 'double for loop' for decreasing operation time.

for i in range(0,len(Dataframe1)):
    for j in range(0,len(Dataframe2)):
        if Dataframe1['col1'][i]-Dataframe2['col2'][j]<0:
            tmp_Dataframe1['col1'][i]=Dataframe2['col3'][j-1]
            break
print(tmp_Dataframe1)
  • Two Dataframe
  • Dataframe_1 one float column and one string column
  • Dataframe_2 three float column and one string column
  • if First Dataframe_1 string==Dataframe_2 string (It's OK, I use Filter Function at first)
  • find index for min value Dataframe_2 float column_1- Dataframe_1 float column (but range in >=0)
  • output Dataframe_2 float column_3 (I use for loop, but I want to optimize these parts)
0 Answers
Related