1 of 15

Lecture 3

Tables

DATA 8

Summer 2024

2 of 15

Announcements

  • Lab 1 is due tomorrow @ 11 PM (59 min grace period)
  • HW 1 is due tomorrow @ 11 PM (59 min grace period)
    • Submit tonight for a bonus!
  • TA Office Hours start today @ Warren Hall
  • Small-group tutoring section sign-ups released Friday and begin next week

3 of 15

Python

4 of 15

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 15

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 15

Names

7 of 15

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 15

Functions

9 of 15

Anatomy of a Call Expression

f ( 27)

What function to call

Argument to the function

"Call f on 27."

10 of 15

Anatomy of a Call Expression

max ( 15 , 27 )

What function to call

First argument

Second argument

(Demo)

11 of 15

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 15

How many errors are in this code?

Click Present with Slido or install our Chrome extension to activate this poll while presenting.

13 of 15

Tables

14 of 15

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)

15 of 15

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
    • Instead of the label(s), you can also use the column index(es) (see the Python Reference)