Python Pandas- Merging two data frames based on an index order
<p>I have two pandas data frames. The first is:</p>

<pre><code>df1 = pd.DataFrame({"val1" : ["B2","A1","B2","A1","B2","A1"]})
</code></pre>

<p>The second data frame is: </p>

<pre><code>df2 = pd.DataFrame({"val1" : ["A1","A1","A1","B2","B2","B2"],
                    "val2" : [10, 13, 16, 11, 20, 22]})
</code></pre>

<p>I would like to merge the two together in a way in which the row ordering from df1 is used and the values from df2 follow this ordering. Ideally, I would like it to look like this:</p>

<pre><code>df_final = pd.DataFrame({"val1" : ["B2","A1","B2","A1","B2","A1"],
                         "val2" : [11, 10, 20, 13, 22, 16]})
</code></pre>

<p>I've tried using the merge function with left_on and right_on, but I don't get the output I'm looking for. Any help would be greatly appreciated. </p>