1 of 10

Lecture 6: Pandas DataFrames

Autumn 2026

1

Sli.do

#cse163

Questions?

Icebreaker

Favorite outdoor activity?

CSE 163

CSE 163: Pandas DataFrames

​

​

2 of 10

Announcements

  • Homework 2 due Tuesday, October 20 at 11:59pm on Gradescope
  • Programming Practice 2 due Sunday October 18 at 11:59pm on Gradescope
    • You can submit as many times before the deadline
    • Smaller programming practice problems on a similar level as in-class exercises

2

Questions?

CSE 163: Pandas DataFrames

​

​

3 of 10

Today’s Roadmap

  1. What is Pandas?
  2. DataFrames
  3. Accessing Columns
  4. Filtering

3

CSE 163: Pandas DataFrames

​

​

4 of 10

Importing Modules

  • Importing allows us to use the contents defined in another Python file, module, or package.

4

# 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()

​

CSE 163: Pandas DataFrames

​

​

5 of 10

What is pandas?

pandas is a widely-used Python library for working with tabular data.

  • In pandas, data is stored as a DataFrame, which is a collection of columns called series) with associated column names

5

Whereas last lecture we stored stores a list of row dictionaries, pandas stores a collection of columns.

CSE 163: Pandas DataFrames

​

​

6 of 10

Importing Data

We can easily import a CSV file as a pandas DataFrame with pd.read_csv �(pd is the standard alias for pandas)

6

df = pd.read_csv('filename.csv')

DataFrame object

Use df or df.head() at the end of a code cell to display the DataFrame

CSE 163: Pandas DataFrames

​

​

7 of 10

Accessing Columns

pandas enables the selecting and modifying of columns using the df[col_name] syntax.

7

Changing a Column

Selecting a Column

df['column1']

df['column1'] = vals

calls_df['Address']

calls_df['New Column'] = 1

Example

CSE 163: Pandas DataFrames

​

​

8 of 10

Filtering

A common data processing task is to filter the rows in a table to only those matching a certain condition.

8

condition = df[col_name] == 'target value'

​

df[condition]

condition is a Series of boolean values

select only the rows where the corresponding value in condition is True

CSE 163: Pandas DataFrames

​

​

9 of 10

Filtering with Masks

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

9

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)]

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

CSE 163: Pandas DataFrames

​

​

10 of 10

Accessing Data in Pandas

  • Access through a Series
  • Access through a DataFrame
  • Indexers can be: a single value, a list of values, a slice, a mask, or a colon (:) to select all values
    • Slicing is inclusive in Pandas!

10

series[<indexer>]

df[<indexer>]

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

CSE 163: Pandas DataFrames

​

​