Lecture 12
Table Examples
DATA 8
Fall 2023
Announcements
Table Review
Important Table Methods
t.select(column, …) or t.drop(column, …)
t.take([row_num, …]) or t.exclude([row_num, …])
t.sort(column, descending=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)
Table Practice
Join for Value Annotation
(Demo)
One common use of t.join(_, u, _):
Pivot
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
Group or Pivot?
Bike Sharing in SF Bay Area
(Demo)
Hourly bike sharing in the Bay Area began with a pilot program in 2014-2015 that produced a public dataset.
by Bjorn Vermeersch