1 of 11

CSE 163

Geopandas�

Suh Young Choi�

🎶 Listening to: Johnny Cash

💬 Before Class: What is your favorite world flag?

2 of 11

Announcements

Midterm evaluations have opened!

  • Will be open today (7/24) – Wednesday (7/26)
  • If >70% of the class fills it out, everyone gets an extra day on HW4!
  • Feedback also helps us out a ton!!

Checkpoint 4 due tonight

HW4 and LR4 due on Thursday

Bonus Dataset Finding Activity releases after class—due next Monday (7/31)

2

3 of 11

Checking in with the Check-ins

Checkpoint Tokens and Lesson completions now on Canvas

  • Checkpoint Tokens have been automatically applied to the earliest missed checkpoint
  • Double-check that you have the correct number of completed lessons, CTs, and used CTs!

Key topics for the LRs

  • Will add these to the slides as they are posted on the website
  • Likely won’t spend time going over each one in detail during class

3

4 of 11

This Time

  • Geospatial data
  • Using Geopandas

Last Time

  • Magic methods
  • os
  • HW4 concepts

4

5 of 11

Geopandas

  • Exactly like pandas, but with some extra features for geo data
  • Types
    • GeoDataFrame
    • GeoSeries

5

import geopandas as gpd

df = gpd.read_file('data_file.shp')

df.plot(column='some_col', legend=True)

plt.savefig('plot.png')

6 of 11

Important!

  • .shp should be used to make GeoDataFrames!
  • .csv should be used to make DataFrames!

6

import geopandas as gpd

import pandas as pd

gdf = gpd.read_file('data_file.shp’)

df = pd.read_csv('data.csv’)

# Don’t do this!!

gdf = gpd.read_file('data.csv’)

7 of 11

zip

  • zip is a helpful built-in function to help you combine lists

  • Note: zip does not return a list! It returns a generator
    • Can only access the values by iterating over them
    • Can only be used once! Iterating “consumes” the series

7

x = [1,2,3]

y = [4,5,6]

zip(x, y)

[(1,4), (2,5), (3,6)]

8 of 11

Matplotlib

  • Before, we were using a lot of matplotlib stuff blindly
  • Default plots gets plotted on a global figure (think canvas)
    • Multiple plots would overwrite each other
  • You have to do extra work to get more information on the same set of axes.

8

ax

fig

fig, ax = plt.subplots(1)

<plot1>(ax=ax)

<plot2>(ax=ax)

fig.savefig('plot.png')

plot1

plot2

9 of 11

Hurricane Florence

9

10 of 11

LR topics may include:

  • Geospatial data
  • .zip and converting to Point/geometry
  • Plotting on multiple axes and subplots

10

11 of 11

Before Next Time

  • Complete Lesson 16
    • Remember not for points, but do go towards Checkpoint Tokens
  • CP4 due tonight
  • Fill out the midterm evals!
  • Resub cycle closes tomorrow (last day to resubmit HW1)

Next Time

  • Two special Geopandas functions

11