Python DataFrame Transform Rows to Column
<p>I have a csv that stores information about a particular object and Date. </p>

<pre><code>Device  Date        Category    Amount
Pen     01/01/2014  A           12
Pen     01/01/2014  B           42
Pen     01/01/2014  C           10
Pen     01/01/2014  D           5
Pen     02/01/2014  A           7
Pen     02/01/2014  B           52
Pen     02/01/2014  C           1
Pen     02/01/2014  D           7
Pencil  01/01/2014  A           22
Pencil  01/01/2014  B           42
Pencil  01/01/2014  C           70
Pencil  01/01/2014  D           8
</code></pre>

<p>I want to read it into a DataFrame and make Category a column and Amounts for a specific device and date a row. This will make the dataset much smaller. </p>

<pre><code>Device  Date        A   B   C   D
Pen    01/01/2014   12  42  10  5
Pen    02/01/2014   7   52  1   7
Pencil  01/01/2014  22  42  70  8
</code></pre>

<p>using <code>groupby</code> and <code>unstack</code></p>

<pre><code>df.groupby(['Device', 'Date', 'Category'])['Amount'].sum().unstack().reset_index()
</code></pre>

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

python pandas dataframe