Sort DataFrame with pandas | Python sort_values Tutorial
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This code demonstrates how to sort a pandas DataFrame based on column values. The sort_values method allows sorting data in ascending (default) or descending order.
Steps:
- Create a DataFrame from a dictionary of data
- Call
df.sort_values(by='age')to sort by age - Call
df.sort_values(by='salary')to sort by salary
This method is essential for data analysis and spotting trends.