Summarising and reshaping
Sorting and ranking, value counts, grouping with aggregation and transform, and reshaping with pivot_table, melt and crosstab.
About 6 hours of study
Learning objectives
- Sort, rank and count values
- Group and aggregate data
- Reshape between long and wide tables
Lessons
- 1
Sorting, ranking and counting Intermediate
Ordering rows with sort_values and sort_index, sorting by several columns in different directions, where missing values go, ranking with ties, the top rows with nlargest, and counting values with value_counts.
- 2
groupby: split, apply, combine Intermediate
Grouping rows by one or more keys and summarising each group with sum, mean, count, size and agg, the difference between count and size, transform for per-row results, and filter for keeping whole groups.
- 3
Reshaping: pivot_table, melt and crosstab Advanced
Turning long data into a wide grid with pivot and pivot_table (and why duplicates need an aggregation), turning wide data back into long rows with melt, and counting combinations with crosstab, with margins for totals.
Module practice
- pandas: Sort by several columnsEasy
- pandas: value_counts and its optionsMedium
- pandas: Rank with every tie methodHard
- pandas: Total per groupEasy
- pandas: Several aggregations per groupMedium
- pandas: transform and filterHard
- pandas: Melt a wide tableEasy
- pandas: A pivot table with aggregationMedium
- pandas: crosstab with marginsHard
Module quiz
‹ Selecting, cleaning and transformingCombining tables, text and dates ›