Sort rows of DataFrame by duplicate
<p>How can I sort a DataFrame so that rows in the duplicate column are &quot;recycled&quot;?</p>
<p>For example, my original DataFrame looks like this:</p>
<pre><code>In [3]: df
Out[3]: 
    A  B
0  r1  0
1  r1  1
2  r2  2
3  r2  3
4  r3  4
5  r3  5
</code></pre>
<p>I would like it to turn to:</p>
<pre><code>In [3]: df_sorted
Out[3]: 
    A  B
0  r1  0
2  r2  2
4  r3  4
1  r1  1
3  r2  3
5  r3  5
</code></pre>
<p>Rows are sorted such that rows in columns <code>A</code> are in a &quot;recycled&quot; fashion.</p>
<p>I have searched APIs in Pandas, but it seems there isn't any proper method to do so. I can write a complicated function to accomplish this, but just wondering is there any smart way or existing pandas method can do this? Thanks a lot in advance.</p>
<p>Update:
Apologies for a wrong statement. In my real problem, column <code>B</code> contains string values.</p>