CSE 163
Section XX
TA 1 & TA 2
Question of the Day: If you could travel anywhere in the world right now, where would you go?
Housekeeping 🏡
Game Plan
What We’ll Cover Today
Recap
What we’ve learned so far:
Geospatial Data
GeoDataFrame:
import geopandas as gpd
df = gpd.read_file('file.shp')
df = gpd.read_file(DATA_FILE)
sa = df[df['CONTINENT'] == 'South America’]
sa.plot(column='POP_EST', legend=True)
Subplots
Subplots
Figure: the big canvas
Axes: various parts of that big canvas
import matplotlib.pyplot as plt
axs = [[ax1, ax2, ax3], [ax4, ax5, ax6]]
fig, axs = plt.subplots(nrows=2, ncols=3)
Dissolve
7
SettingWithCopy warning
What is it, and how can we work around it?
Let’s look at an example!
This code produces a SettingWithCopy warning!
import pandas as pd
tas = pd.DataFrame([
{‘first’: ‘Arona’, ‘last’: ‘Cho’, ‘pet’: ‘cat’},
{‘first’: ‘Renusree’, ‘last’: ‘Chittella’, ‘pet’: ‘dog’},
{‘first’: ‘Arpan’, ‘last’: ‘Kapoor’, ‘pet’: ‘cat’},
{‘first’: ‘Hannah’, ‘last’: ‘Chiu’, ‘pet’: ‘dog’},
{‘first’: ‘Asmi’, ‘last’: ‘Sathaye’, ‘pet’: ‘dog’},
{‘first’: ‘Mia’, ‘last’: ‘Wang’, ‘pet’: ‘cat’}
])
dog_mask = tas[‘pet’] == ‘dog’
dog_lovers = tas[dog_mask]
dog_lovers[‘full_name’] = dog_lovers[‘first’] + ‘ ‘ + dog_lovers[‘last’]
# uh oh!
What is it?
dog_lovers = tas[dog_mask]) did not cause the error because they only involve selection, not modification, so there’s no risk of unintended data changes at that point.
What should we do instead?
dog_lovers = tas[dog_mask].copy()
Spatial Join and merge
Merge
Merge for left vs right
When merging GDF with regular DF, the order matters!
Keep gdf on the left when you want to preserve geometry and map/plot
(important for __init__ in THA 5)
What’s the difference?
Practice problems!
Open up geospatial-data-win26.ipynb
Solutions!
Solutions!
Project Part 2: EDA Check In
Now that we’re a little over halfway through the quarter, think about and discuss the following with your group:
After discussing, group members should ask follow-up questions or offer insights!
Section Code: