For a given data frame:
UUT testa testb testc testd
DateTime
2017-11-21 18:47:29 1.0 1.0 1.0 3.0
2017-11-21 18:47:30 1.0 2.0 1.0 4.0
2017-11-21 18:47:31 1.0 2.0 5.0 2.0
2017-11-21 18:47:32 1.0 2.0 5.0 1.0
2017-11-21 18:47:33 1.0 2.0 5.0 4.0
2017-11-21 18:47:34 1.0 2.0 5.0 1.0
how can I manually rearrange the columns anyway I want it for example if I want to the following sequence:
testc, testd, testa, testb
So the table and the plot will be in this way:
UUT testc testd testa testb
DateTime
2017-11-21 18:47:29 1.0 3.0 1.0 1.0
2017-11-21 18:47:30 1.0 4.0 1.0 2.0
2017-11-21 18:47:31 5.0 2.0 1.0 2.0
2017-11-21 18:47:32 5.0 1.0 1.0 2.0
2017-11-21 18:47:33 5.0 4.0 1.0 2.0
2017-11-21 18:47:34 5.0 1.0 1.0 2.0
In a PivotTable, click the small arrow next to Row Labels and Column Labels cells. Click a field in the row or column you want to sort. on Row Labels or Column Labels, and then click the sort option you want. To sort data in ascending or descending order, click Sort A to Z or Sort Z to A.
If you go to Data -> Sort , you can add multiple levels of sorting, i.e. "I want to sort by revenue, then total quantity, then alphabetic Product order, etc." When in pivot table sorting, even if you only have one Row column (say Product), you cannot sort by multiple columns in values.
You can sort pandas DataFrame by one or multiple (one or more) columns using sort_values() method and by ascending or descending order. To specify the order, you have to use ascending boolean property; False for descending and True for ascending. By default, it is set to True.
You can use:
df = df.reindex_axis(['testc','testd', 'testa','testb'], axis=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With