0

I am quite new to pandas (working with 3rd party code, forced to use it!), and I have a dataframe which looks like so:

name_id    cookie_id    file_name_id
John       56           /some/loc
Doe        45           /some/loc2
John       67           /some/loc3
hilary     768          /some/loc4
wendy      8            /some/loc3
hilary     4            /some/loc4

I would like to sort them by the name_id like so:

name_id    cookie_id    file_name_id
Doe        45           /some/loc2
John       56           /some/loc
John       67           /some/loc3
hilary     768          /some/loc4
hilary     4            /some/loc4
wendy      8            /some/loc3

I am looking at:

df.sort_values(by=['name_id'])

and it does seem to give me the correct answer, but since I am new to pandas, I am afraid there might be some gotchas I need to aware of.

1

1 Answer 1

1

df.sort_values(by=['name_id']) should be perfectly fine to use. Watch out for spaces in the beginning of the name_id string as those would be sorted first. For example, " wendy" would be placed in the top in your case.

Sign up to request clarification or add additional context in comments.

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.