1 of 15

Lecture 10

Groups

DATA 8

Fall 2023

2 of 15

Announcements

  • Lab 4 due tonight at 11pm.
  • HW 5 due Wednesday 9/20 at 11pm
  • Project 1 due Friday 9/29
    • Checkpoint due Friday 9/22
    • World population through data
  • Sahai OH: Mondays, 5-7pm @ FSM Cafe

3 of 15

How to Get to FSM

4 of 15

Functions

(Demo)

5 of 15

Apply

6 of 15

Apply

apply

  1. Calls a function on every element in the input column(s)
  2. Produces an array containing the output of the function on each input column element.
  3. First argument: Function to apply
  4. Other arguments: Specified input column(s)

table_name.apply(function_name, 'column_label(s)')

(Demo)

7 of 15

Prediction

(Demo)

8 of 15

Prediction Accuracy

(Demo)

9 of 15

Discussion Questions

  1. How could we take sex into account when making predictions?
  2. Do we make smaller errors on average when we do this?

(Demo)

10 of 15

11 of 15

Grouping

12 of 15

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.

  • First argument: Which column to group by
  • Second argument: (Optional) How to combine values
    • len — number of grouped values (default)
    • list — list of all grouped values
    • sum — total of all grouped values

(Demo)

13 of 15

Lists

14 of 15

Lists are Generic Sequences

A list is a sequence of values (just like an array), � but the values can have different types

[2+3, 'four', Table().with_column('K', [3, 4])]

  • Lists can be used to create table rows.
  • If you create a table column from a list, it will be converted to an array automatically

(Demo)

15 of 15

Cross-Classification

(Demo)