Reputation: 289
I have a data frame index (Grade) below, and it is sorted by alphabetical order. Is there a way I can decide on the arrangement such that A to H is above, followed by '2-6 mths' and '1 mth'? For columns, I know it is easy simply by df=df[[col1,col2]]
Upvotes: 0
Views: 1456
Reputation: 62007
You almost answered your own question. You make the column of interest the index of the dataframe and then use a similar mechanism as you would for sorting columns as you would for rows except with the .loc
operator.
df.loc[['A','B','C','D','E','F','G','H','2-6mths', '1 mth']]
And then you can just reset the index to move grade back as a column.
df.reset_index()
Upvotes: 2