1 of 11

Lecture 12

Table examples

DATA 8

Spring 2019

Slides created by John DeNero (denero@berkeley.edu) and Ani Adhikari (adhikari@berkeley.edu)

2 of 11

Announcements

3 of 11

Combining Table Methods

4 of 11

Important Table Methods

t.select(column, …) or t.drop(column, …)

t.take([row, …]) or t.exclude([row, …])

t.sort(column, descending=False, distinct=False)

t.where(column, are.condition(...))

t.apply(function, column, …)

t.group(column) or t.group(column, function)

t.group([column, …]) or t.group([column, …], function)

t.pivot(cols, rows) or t.pivot(cols, rows, vals, function)

t.join(column, other_table, other_table_column)

5 of 11

Bikes

(Demo)

6 of 11

Maps

(Demo)

7 of 11

Maps

A table containing columns of latitude and longitude values can be used to generate a map of markers

Applies to all features:

color='blue'

size=200

_______.map_table(table, ...)

Either Marker or Circle

Column 0: latitudes

Column 1: longitudes

Column 2: labels

Column 3: colors

Column 4: sizes

8 of 11

Review

9 of 11

Spring 2016 Midterm, Q2(b)

  • The name of the station where the most rentals ended (assume no ties).
  • The number of stations for which the average duration ending at that station was more than 10 minutes.

(Demo)

10 of 11

Advanced Where (Optional)

11 of 11

Comparison Operators

The result of a comparison expression is a bool value

x = 2 y = 3

x > 1 x > y y >= 3

x == y x != 2 2 < x < 5

Assignment statements

Comparison expressions

(Demo)

t.where(array_of_bool_values) returns a table with only the rows of t for which the corresponding bool is True.