I created a pivot table using:
table2 = pandas.pivot_table(df, index=['Salesperson'], values=['Gross Sales', 'Gross Profit'], aggfunc=numpy.sum)
table2['Profit Margin'] = table2['Gross Profit'] / table2['Gross Sales']
table2_rounded = table2.round({'Gross Profit': 2, 'Gross Sales': 2, 'Profit Margin': 2})
which gives me:
in: table2.info
out: Salesperson Gross Profit Gross Sales Profit Margin
((((values as row data))))
as columns. HOWEVER - Gross Sales should display before Gross Profit. How do I change the order of the non-index columns? The dataframe was 1000 rows long before I pivoted. I searched high and low for a solution. This seems rather basic (or should be...)