Concat two Pandas dataframes without sorting on initial columns
<p>I have two data frames:</p>

<p>Dataframe A</p>

<pre><code>index  ID_1  ID_2   Value
0       1     1      1.0
1       1     2      1.2
2       1     3      1.3
</code></pre>

<p>DataFrame B</p>

<pre><code>index  ID_1  ID_2   Value
0       1     2      1.0
1       1     1      1.2
2       1     3      1.3
</code></pre>

<p>And each is sorted by ID_1, then by Value.</p>

<p>I want to merge or concatenate the two dataframes so that I can easily determine where ID_2 in dataframe A and dataframe B are not the same - so determine when the sorting I have highlights a difference in the order of the ID_2 column.</p>

<p>I have tried to use pd.concat several different ways and I always get this result:</p>

<pre><code>index  ID_1  ID_2   Value    ID_1  ID_2   Value
0       1     1      1.0      1     1      1.2
1       1     2      1.2      1     2      1.0
2       1     3      1.3      1     3      1.3  
</code></pre>

<p>Rather than what I want:</p>

<pre><code>index  ID_1  ID_2   Value    ID_1  ID_2   Value
0       1     1      1.0      1     2      1.0
1       1     2      1.2      1     1      1.2
2       1     3      1.3      1     3      1.3  
</code></pre>

<p>Any ideas?  I have tried it with different column names, etc.</p>

<p>Edit:</p>

<p>The solution proposed below of course works, but one must remember to do <code>reset_index(drop=True)</code> on the dataframe to have the indexes reset after the sorting.</p>

<p>this works for me<br>
assuming <code>'index'</code> is the index for both <code>A</code> and <code>B</code></p>

<pre><code>pd.concat([A, B], axis=1)
</code></pre>

<p><a href="http://i.stack.imgur.com/seaPi.png" rel="nofollow"><img src="http://i.stack.imgur.com/seaPi.png" alt="enter image description here"></a></p>

python pandas dataframe