Lecture 10
Groups
DATA 8
Fall 2018
Slides created by John DeNero (denero@berkeley.edu) and Ani Adhikari (adhikari@berkeley.edu)
Announcements
Project 1: World Progress
Example: Prediction
Apply with Multiple Columns
From last time: discussion Q
You have data about daily temperatures as shown. Which type of chart would you use to answer each question?
Apply
The apply method creates an array by calling a function on every element in one or more input columns
table_name.apply(one_arg_function, 'column_label')
table_name.apply(two_arg_function,
'column_label_for_first_arg',
'column_label_for_second_arg')
apply called with only a function applies it to each row
(Demo)
Grouping by One Attribute
Grouping by One Column
The group method aggregates all rows with the same value for a column into a single row in the resulting table.
(Demo)
Cross-Classification
Grouping By Multiple Columns
The group method can also aggregate all rows that share the combination of values in multiple columns
(Demo)
Pivot Tables
Pivot
(Demo)
Challenge Question
Which NBA teams spent the most on their “starters” in 2015-2016?
Assume the “starter” for a team & position is the player with the highest salary on that team in that position.
(Demo)
Take-Home Question
Generate a table of the names of the starters for each team