Member-only story
Pandas dataframe ordering with examples using sort_values().
Often times, you need some form of ordering in a result set. In the SQL world, without anORDER BY
clause, query results order is not guaranteed. What if you are working in the pandas world? Fear not. You can order DataFrame results in a similar fashion as that of ORDER BY
using the sort_values()
function. Let’s learn together by example…
Note: All data, names or naming found within the database presented in this post, are strictly used for practice, learning, instruction, and testing purposes. It by no means depicts actual data belonging to or being used by any party or organization.
OS and DB used:
- Xubuntu Linux 18.04.2 LTS (Bionic Beaver)
- PostgreSQL 11.5
Self-Promotion:
If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!
For a working data set, I’ll use the pandas read_csv()
function and load a CSV files’ contents into a DataFrame object:
>>> import pandas as pd
>>> df = pd.read_csv(‘/home/linux_user/Practice Data/Fitness_DB_Data/july_2019_hiking_stats.csv’)