Pandas reorder data
<p>This is probably an easy one using pivot, but since I am not adding the numbers (every row is unique) how should I go about doing this?</p>

<p>Input:</p>

<pre><code>      Col1   Col2 Col3
0    123.0   33.0  ABC
1    345.0   39.0  ABC
2    567.0  100.0  ABC
3    123.0   82.0  PQR
4    345.0   10.0  PQR
5    789.0   38.0  PQR
6    890.0   97.0  XYZ
7    345.0   96.0  XYZ
</code></pre>

<p>Output:</p>

<pre><code>      Col1    ABC   PQR   XYZ
0    123.0   33.0  82.0   NaN
1    345.0   39.0  10.0  96.0
2    567.0  100.0   NaN   NaN
3    789.0    NaN  38.0   NaN
4    890.0    NaN   NaN  97.0
</code></pre>

<p>And could I get this output in dataframe format then pls? Thanks so much for taking a look!</p>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot.html" rel="nofollow"><code>pivot</code></a>:</p>

<pre><code>print (df.pivot(index='Col1', columns='Col3', values='Col2'))
Col3     ABC   PQR   XYZ
Col1                    
123.0   33.0  82.0   NaN
345.0   39.0  10.0  96.0
567.0  100.0   NaN   NaN
789.0    NaN  38.0   NaN
890.0    NaN   NaN  97.0
</code></pre>

<p>Another solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.unstack.html" rel="nofollow"><code>unstack</code></a>:</p>

<pre><code>print (df.set_index(['Col1','Col3'])['Col2'].unstack())
Col3     ABC   PQR   XYZ
Col1                    
123.0   33.0  82.0   NaN
345.0   39.0  10.0  96.0
567.0  100.0   NaN   NaN
789.0    NaN  38.0   NaN
890.0    NaN   NaN  97.0
</code></pre>

<hr>

<p>EDIT by comment:</p>

<p>Need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table</code></a>:</p>

<pre><code>print (df.pivot_table(index='Col1', columns='Col3', values='Col2'))
Col3     ABC   PQR   XYZ
Col1                    
123.0   33.0  82.0   NaN
345.0   39.0  10.0  96.0
567.0  100.0   NaN   NaN
789.0    NaN  38.0   NaN
890.0    NaN   NaN  97.0
</code></pre>

<p>You can also check <a class='doc-link' href="http://stackoverflow.com/documentation/pandas/1463/reshaping-and-pivoting/4771/pivoting-with-aggregating#t=201610030626083995389">SO documentation</a>.</p>

<p>Another faster solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a>, aggregating <code>mean</code> (by default <code>pivot_table</code> aggreagate <code>mean</code> also), convert to <code>Series</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.squeeze.html" rel="nofollow"><code>DataFrame.squeeze</code></a> and last <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.unstack.html" rel="nofollow"><code>unstack</code></a>:</p>

<pre><code>print (df.groupby(['Col1','Col3']).mean().squeeze().unstack())
Col3     ABC   PQR   XYZ
Col1                    
123.0   33.0  82.0   NaN
345.0   39.0  10.0  96.0
567.0  100.0   NaN   NaN
789.0    NaN  38.0   NaN
890.0    NaN   NaN  97.0
</code></pre>

python pandas dataframe