1 of 15

Lecture 7

Charts

DATA 8

Fall 2020

2 of 15

Announcements

  • HW 2 due tomorrow night, 9/12
    • Turn in by 11:59PM tonight for a bonus point!
  • HW3 due next Thursday 9/17
  • Midterm will be on October 16, 7-9pm
    • If the time is an issue in your timezone, please fill out conflict form (see Piazza)
  • Array primer on Piazza

​

3 of 15

Weekly Goals

  • Wednesday
    • Table review
  • Today
    • Working with Census data
    • Visualizing data
    • Distributions
  • Monday
    • Visualizing two kinds of distributions
    • Proportions as areas

​

4 of 15

Table Review

5 of 15

Manipulating Rows

  • t.sort(column) sorts the rows in increasing order
  • t.sort(column, descending=True)sorts the rows in decreasing order
  • t.take(row_numbers) keeps the numbered rows
    • Each row has an index, starting at 0
  • t.where(column, are.condition) keeps all rows for which a column's value satisfies a condition
  • t.where(column, value) keeps all rows �for which a column's value equals some particular value
    • Same as t.where(column, are.equal_to(value))

​

6 of 15

Census Data

7 of 15

The Decennial Census

  • Every ten years, the Census Bureau counts how many people there are in the U.S.

​

  • In between censuses, the Bureau estimates how many people there are each year.

​

  • Article 1, Section 2 of the Constitution:
    • “Representatives and direct Taxes shall be apportioned among the several States … according to their respective Numbers …”

8 of 15

Census Table Description

  • Values have column-dependent interpretations
    • The SEX column: 1 is Male, 2 is Female
    • The POPESTIMATE2010 column: 7/1/2010 estimate
  • In this table, some rows are sums of other rows
    • The SEX column: 0 is Total (of Male + Female)
    • The AGE column: 999 is Total of all ages
  • Numeric codes are often used for storage efficiency
  • Values in a column have the same type, but are not necessarily comparable (AGE 12 vs AGE 999)

9 of 15

Analyzing Census Data

Leads to the discovery of interesting features and trends in the population

(Demo)

10 of 15

Numerical Data

11 of 15

https://en.wikipedia.org/wiki/C-3PO

Anthony Daniels,

actor

12 of 15

Plotting Two Numerical Variables

Line graph: plot

Scatter plot : scatter

(Demo)

13 of 15

When to use a line vs scatter plot?

  • Use line plots for sequential data: if...
    • ...your x-axis has an order
    • ...sequential differences in y values are meaningful
    • ...there’s only one y-value for each x-value
    • Usually: x-axis is time or distance

​

  • Use scatter plots for non-sequential data
    • When you’re looking for associations

​

14 of 15

Categorical Data

(Demo)

15 of 15

How Do You Generate This Chart?

Top 10 highest grossing movies

Number of years since release