1 of 12

CSE 163

Pandas & DataFrames

Arpan Kapoor�Summer 2026��

slido.com

#2348882

2 of 12

Announcements

  • Programming Practice 1 due tomorrow, July 2nd at 11:59pm!
    • Programming Practice 2 also releases tomorrow!
  • Homework 1: Processing due Friday, July 3rd at 11:59pm!
    • Homework 2: Pokemon also releases on Friday
  • No class on Friday!

slido.com

#2348882

3 of 12

Importing

  • Importing allows us to use the contents defined in another Python file/module/package
    • Generally there are three ways we can import!

# Method 1: Import module

import module

module.function()

# Method 2: Import and rename module

import module as m

m.function()

# Method 3: Import specific function from module

from module import function

function()

slido.com

#2348882

4 of 12

DataFrame

  • One of the basic data types from pandas is a DataFrame!

id

year

month

day

latitude

longitude

name

magnitude

0

nc72666881

2016

7

27

37.672333

-121.619000

California

1.43

1

us20006i0y

2016

7

27

21.514600

94.572100

Burma

4.90

2

nc72666891

2016

7

27

37.576500

-118.859167

California

0.06

Index (row)

Columns

slido.com

#2348882

5 of 12

Series

  • A Series is like a 1-dimensional DataFrame (no columns!)
    • Has an index
    • You can think of it like a fancy dictionary/list hybrid

df['name']

0

California

1

Burma

2

California

df['name'][1] # 'Burma'

slido.com

#2348882

6 of 12

Series Operations

  • You can do Series-wide operations without loops!

0

California :)

1

Burma :)

2

California :)

df['name’] += “ :)”

df[‘magnitude’] *= 2

0

2.86

1

9.80

2

0.12

slido.com

#2348882

7 of 12

Series Operations

  • What does this operation turn into?

0

California

1

Burma

2

California

df['name’] == “Burma”

slido.com

#2348882

8 of 12

Series Operations

  • What does this operation turn into?

False

True

False

0

California

1

Burma

2

California

df['name’] == “Burma”

slido.com

#2348882

9 of 12

Series Operations

  • What does this operation turn into?

id

year

month

day

latitude

longitude

name

magnitude

0

nc72666881

2016

7

27

37.672333

-121.619000

California

1.43

1

us20006i0y

2016

7

27

21.514600

94.572100

Burma

4.90

2

nc72666891

2016

7

27

37.576500

-118.859167

California

0.06

df['name’] == “Burma”

slido.com

#2348882

10 of 12

Filtering

  • We can use a bool Series to select specific rows from the dataset

Can use multiple filters: & (and), | (or), ~ (not)

mask = df['magnitude'] > 5

df[mask]

# Same as: data[data['magnitude'] > 5]

id

year

month

day

latitude

longitude

name

magnitude

30

us20006i18

2016

7

27

-24.286000

-67.864700

Chile

5.60

114

us20006i35

2016

7

27

36.492200

140.756800

Japan

5.30

421

us1000683b

2016

7

28

-16.824200

-172.515800

Tonga

5.10

df[(df['magnitude'] > 5) & ~(df['day'] == 27)]

slido.com

#2348882

11 of 12

Location: Accessing Data in Pandas

  • Series
  • DataFrame
  • Options for indexers:
    • A single value
    • A list of values or slice
    • A mask
    • : (colon) to select all values

The end of a slice is inclusive in Pandas, unlike in standard Python!

series[<indexer>]

df[<indexer>]

df.loc[<row indexer>, <column indexer>]

12 of 12

Lesson Recap

  • Imports
    • A way for us to get functionality from modules we did not write ourselves!
  • Pandas
    • New data types - DataFrames and Series
    • More tabular-looking than lists of dictionaries
    • Lots of great functional tools for data cleaning, analysis, and visualization!

slido.com

#2348882