Sort data and finding maximum. The following shows how to sort data and find maximum using pandas module.
Importing Module:
import pandas as pd
import sys
Code:
births_df = pd.read_csv('Data/births.csv', names=['Names', 'Births'])
births_df
Output:
Names | Births | |
---|---|---|
0 | Bob | 968 |
1 | Jessica | 155 |
2 | Mary | 77 |
3 | John | 578 |
4 | Mel | 973 |
Sort data:
births_sorted = births_df.sort_values(['Births'], ascending=False)
births_sorted
Output:
Names | Births | |
---|---|---|
4 | Mel | 973 |
0 | Bob | 968 |
3 | John | 578 |
1 | Jessica | 155 |
2 | Mary | 77 |
Code:
births_sorted.head(1)
Output:
Names | Births | |
---|---|---|
4 | Mel | 973 |
Getting Max:
births_df['Births'].max()
Output:
973