0

I'm trying to sort this dataframe based on the 'ID Name'. How do I get the 'ID Name' values in alphabetical order (while keeping the values' corresponding time stamps and comments)?

          ID Name             Time Stamp         Comments
0          W10D12    2015-01-24 16:40:34     RandComment1 
1           W8D13    2015-01-25 11:51:21     RandComment1   
2           W8D15    2015-01-25 11:51:41     RandComment1  
3           W8D22    2015-01-25 11:51:47     RandComment2 
4           W8D23    2015-01-25 11:51:54     RandComment2
5           W8D25    2015-01-25 11:51:59     RandComment2
6           W2D27    2015-01-25 11:52:03     RandComment2
7          W16D12    2015-01-24 16:41:45     RandComment3
8          W10D13    2015-01-25 11:53:06     RandComment4
9           W8D15    2015-01-25 11:53:27     RandComment4
..            ...                    ...              ...

2 Answers 2

1

You can use the dataframe sort functionality, the rest of the columns will follow along:

result = df.sort_index(by=['ID Name'], ascending=[True])
Sign up to request clarification or add additional context in comments.

1 Comment

.sort_values (.sort_values is deprecated)
0

df.sort('ID Name') will sort the DataFrame by rows based on 'ID Name'

you could add a new column that is the sorted ID:

new_col = df['ID Name'].copy()
new_col.sort()
df['sorted ID'] = new_col

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.