1 of 11

Lecture 10

Groups

DATA 8

Spring 2022

2 of 11

Announcements

3 of 11

Prediction

(Demo)

4 of 11

Prediction Accuracy

(Demo)

5 of 11

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?

6 of 11

7 of 11

Grouping

8 of 11

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)

9 of 11

Lists

10 of 11

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)

11 of 11

Cross-Classification

(Demo)