How to reduce the time complexity of this nested loop code in python : <p>Please help me reduce the time complexity of the nested loop in Python</p>

<p>df is a dataframe with say 3 columns, say name,  city and date for eg
rep data frame has the average/means based on 2 columns name and city  from df. I need to reattach the mean from rep to df </p>

<pre><code>for i in range(0,len(rep)):
    for j in range(k,len(df)):
        if df["X"][j] == rep["X"][i]:
           df["Mean"][j] =  rep["Mean"][i]
       else:
           k=j
           break
</code></pre>
