1 of 14

Lecture 3

Tables

DATA 8

Fall 2022

2 of 14

Announcements

  • HW 1 is due Wednesday 8/31 @ 11pm
    • Submit on Tuesday 8/30 for a bonus!
  • Office hours start this week: �http://data8.org/fa22/officehours/
  • Small-group tutoring section signups released early this week

3 of 14

Python

4 of 14

Python

  • Python is popular both for data science & �general software development
  • Mastering the language fundamentals is critical
  • Learn through practice:
    • See some examples & learn the rules
    • Try out variants of those examples yourself
    • Write new code that solves new problems

(Demo)

5 of 14

Review of Python Concepts

  • An expression evaluates to a value
  • Values can be numbers or strings (text); we’ll see lots of other kinds of values soon
  • The syntax (format) of the language is very rigid — even an extra space can cause a syntax error
  • There is particular behavior associated with built-in operators that you need to learn �(e.g., dividing produces 8.0 instead of 8)

6 of 14

Names

7 of 14

Assignment Statements

  • An assignment statement changes the meaning of the name to the left of the = symbol
  • The name is bound to the value of the expression to the right of the = symbol (its current value; not the equation)

hours_per_wk = 24 * 7

Name

Any expression

(Demo)

8 of 14

Functions

9 of 14

Anatomy of a Call Expression

f ( 27)

What function to call

Argument to the function

"Call f on 27."

10 of 14

Anatomy of a Call Expression

max ( 15 , 27 )

What function to call

First argument

Second argument

(Demo)

11 of 14

Review of Function Concepts

  • Some functions require a particular number of arguments (e.g., abs must be called on one value)
  • Arguments can be named in the call expression:�round(number=12.34)�But the names must match the documentation
  • Type a ? after a function name to see its documentation

12 of 14

Tables

13 of 14

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)

14 of 14

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