1 of 8

CSE 163

Dissolve and Joins

��Hunter Schafer

💬Before Class: Are you a cat person or a dog person?

🎵Music: Sammy Rae & The Friends

2 of 8

Geopandas

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

2

import geopandas as gpd

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

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

plt.savefig('plot.png')

3 of 8

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.

3

fig, ax = plt.subplots(1)

<plot1>(ax=ax)

<plot2>(ax=ax)

fig.savefig('plot.png')

4 of 8

Dissolve

  • Exactly the same as a groupby for the the regular columns
    • For the geometry columns, overlays all of the geometries
  • Options for aggfunc
    • ‘first’
    • ‘last’
    • ‘min’
    • ‘max’
    • ‘sum’
    • ‘mean’
    • ‘median’

4

5 of 8

Join

5

tas.merge(grading, left_on='ta_id',

right_on='grader_id')

ta_name

ta_id

Ryan

1

James

2

Nicole

3

grader_id

student_name

2

Flora

3

Paul

1

Wen

3

Andrew

ta_name

ta_id

grader_id

student_name

Ryan

1

1

Wen

James

2

2

Flora

Nicole

3

3

Paul

Nicole

3

3

Andrew

6 of 8

Types of Join

There are interesting questions of what happens if there are rows that don’t “line up”. Different type of joins differ in how to handle this case.

Types of Joins

left.merge(right, left_on=’lcol’, right_on=’rcol’,

how=’type’)

  • Inner (default): Both values must be present
  • Left: If a value from left has no match, add NaNs
  • Right: If a value from right has no match, add NaNs
  • Outer: If a value from either table has no match, add NaNs

6

7 of 8

Hurricane Florence

7

8 of 8

Group Work:

Best Practices

When you first working with this group:

  • Introduce yourself!
  • If possible, angle one of your screens so that everyone can discuss together

Tips:

  • Starts with making sure everyone agrees to work on the same problem
  • Make sure everyone gets a chance to contribute!
  • Ask if everyone agrees and periodically ask each other questions!
  • Call TAs over for help if you need any!

8