1 of 13

Lecture 3

Tables

Fall 2021

2 of 13

Announcements

  • Office hours start this week: http://data8.org/fa21/office-hours.html
  • Tutoring section signups released tomorrow
  • HW 1 is due 9/2, Thursday night
    • Submit on 9/1 (Wednesday) for a bonus point

3 of 13

Weekly Goals

  • Today:
    • Python basics
    • Tables
  • Wednesday:
    • Types of data
    • Arrays
  • Friday:
    • Creating new tables
    • Manipulating columns of tables

4 of 13

Python

5 of 13

Python

  • Python is popular both for data science & �general software development
  • Mastering the language fundamentals is critical
  • Learn through practice, not by reading or listening
  • Follow along: data8.org/fa21

(Demo)

6 of 13

Names

7 of 13

Assignment Statements

  • Statements don't have a value; they perform an action
  • An assignment statement changes the meaning of the name to the left of the = symbol
  • The name is bound to a value (not an equation)

hours_per_wk = 24*7

Name

Any expression

(Demo)

8 of 13

Functions

9 of 13

Anatomy of a Call Expression

f ( 27)

What function to call

Argument to the function

"Call f on 27."

10 of 13

Anatomy of a Call Expression

max ( 15 , 27 )

What function to call

First argument

Second argument

(Demo)

11 of 13

Tables

12 of 13

Table Structure

  • A Table is a sequence of labeled columns
  • Each row represents one individual
  • Data within a column represents one attribute of the individuals

Name

Code

Area (m2)

California

CA

163696

Nevada

NV

110567

Label

Column

Row

(Demo)

13 of 13

Some Table Operations

  • t.select(label) - constructs a new table with just the specified columns
  • t.drop(label) - constructs a new table in which the specified columns are omitted
  • t.sort(label) - constructs a new table with rows sorted by the specified column
  • t.where(label, condition) - constructs a new table with just the rows that match the condition