Lecture 12
Table Examples
DATA 8
Spring 2020
Weekly Goals
Review: Pivot and Join
Pivot
(Demo)
Group or Pivot?
Grouped Table
Pivot Table
For cross-classification:
Joining Two Tables
Drink | Cafe | Price |
Milk Tea | Asha | 5.5 |
Espresso | Strada | 1.75 |
Latte | Strada | 3.25 |
Espresso | FSM | 2 |
Coupon | Location |
10% | Asha |
25% | Strada |
5% | Asha |
drinks
discounts
Cafe | Drink | Price | Coupon |
Asha | Milk Tea | 5.5 | 10% |
Asha | Milk Tea | 5.5 | 5% |
Strada | Espresso | 1.75 | 25% |
Strada | Latte | 3.25 | 25% |
drinks.join('Cafe', discounts, 'Location')
Match rows in this table ...
… using values in this column ...
… with rows in that table ...
… using values in that column.
The joined column is sorted automatically
Columns from both tables
Important Table Methods
t.select(column, …) or t.drop(column, …)
t.take([row_num, …]) or t.exclude([row_num, …])
t.sort(column, descending=False, distinct=False)
t.where(column, are.condition(...))
t.apply(function_name, column, …)
t.group(column) or t.group(column, function_name)
t.group([column, …]) or t.group([column, …], function_name)
t.pivot(cols, rows) or t.pivot(cols, rows, vals, function_name)
t.join(column, other_table, other_table_column)
Examples