1 of 15

CSE 163

Geopandas�

Suh Young Choi

2 of 15

Announcements

THA 4 Peer Reviews due tonight

Checkpoint 4 (Stats, ML, and Maps) open now; due next Monday

Project/Portfolio Part 2 due tomorrow

THA 5: Mapping due next Thursday

No resubmissions on the Creative Component (unless… 👀)

  • Possibility of a Bonus Resubmission Period from 3/11 – 3/13
  • Submit any ONE Technical Component and any ONE Creative Component
  • Doesn’t have to be for the same THA!
  • Course eval goes out on March 2; 65% response rate by 3/9 and everyone gets a bonus resub!

2

3 of 15

This Time

  • Geospatial data
  • Using Geopandas

Last Time

  • Machine Learning
  • Model Evaluation

3

4 of 15

Geospatial Data

  • Simply put, maps!
  • Represents places in the world and accompanying data

4

5 of 15

Shapes

  • These live in the geometry column
  • Lines and/or points that indicate shapes
  • Some examples are given here:

5

6 of 15

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

6

x = [1,2,3]

y = [4,5,6]

zip(x, y)

7 of 15

Geopandas

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

7

import geopandas as gpd

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

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

plt.savefig('plot.png')

8 of 15

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

fig, ax = plt.subplots(1)

<plot1>(ax=ax)

<plot2>(ax=ax)

fig.savefig('plot_together.png')

9 of 15

Matplotlib

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

9

fig, ax = plt.subplots()

<plot1>(ax=ax)

<plot2>(ax=ax)

fig.savefig('plot_together.png')

fig, [ax1, ax2] = plt.subplots(1, 2) # width, height

<plot1>(ax=ax1)

<plot2>(ax=ax2)

fig.savefig('plot_separate.png')

10 of 15

Matplotlib

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

10

fig

ax1

ax2

11 of 15

Matplotlib

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

11

fig

ax1

ax2

12 of 15

Matplotlib

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

12

fig

ax1

ax2

13 of 15

Hurricane Florence

13

14 of 15

Hurricane Florence

14

15 of 15

Before Next Time

Complete Lesson 17

Remember not for points, but do go towards Weekly Tokens

THA 4 Peer Reviews due tonight

Complete Project/Portfolio Part 2!

Go to section tomorrow!!

Next Time

  • Two special Geopandas functions

15