Sorting column label pandas pivot table
<p>Another pandas sort question (tried all current SO ones and didn't find any solutions).</p>

<p>I have a <code>pandas pivot_table</code> like so:</p>

<pre><code>rows = ['Tool_Location']
cols = ['shift_date','Part_Number', 'shift']
pt = df.pivot_table(index='Tool_Location', values='Number_of_parts', dropna=False, fill_value ='0', columns=cols, aggfunc='count')
</code></pre>

<p>produces:</p>

<pre><code>Shift date     10/19
Part_number   40001
shift        first  second  third
tool_loc
T01            0     1     0       
T02            2     1     0 
</code></pre>

<p>I'd like to switch the order of shift labels so it is <code>third first second</code></p>

<p><strong>EDIT:</strong></p>

<p>Getting closer to a solution but not seeing it.</p>

<p>Using:</p>

<pre><code> col_list = pt.columns.tolist()
 output:
 [('10/20/16', 'first'), ('10/20/16', 'second'), ('10/20/16', 'third'), ('10/21/16', 'first'), ('10/21/16', 'second'), ('10/21/16', 'third')]
</code></pre>

<p>Anyone know how to dynamically reorder the items so its:</p>

<pre><code>[('10/20/16', 'third'), ('10/20/16', 'first'), ('10/20/16', 'second'), ('10/21/16', 'first'), ('10/21/16', 'second'), ('10/21/16', 'second')]
</code></pre>

<p>Because then we could reorder the columns by using pt = pt[col_list]</p>