GEOG 30323: Data Analysis & Visualization
2026-11-10
Conversion between DMS and decimal degrees:
\[DD = D + \frac{M}{60} + \frac{S}{3600}\]
GeoPandas: Python package that extends pandas to represent geographic objects as GeoDataFrames
Key column: geometry, which represents the geometry type of the data (point, line, or polygon) and the sequence of coordinates
Google Colab has many Python packages you’ll need for your work pre-installed, but not all!
Packages can be installed from the Python Package Index using the pip command prefaced with an exclamation mark
gp.GeoDataFrame(): function used to generate the GeoDataFrame, which can take an existing pandas DataFrame as its first argument
Parameters:
geometry: how to represent the data as a geographic object. We use the gp.points_from_xy() function here to “make” the geometry from existing Longitude and Latitude columns.crs: a code that specifies the dataset’s coordinate reference system. Most coordinate systems can be represented by 4- or 5-digit codes (see https://spatialreference.org/)Extension to the JSON format that encodes geographic coordinates for datasets
mxgeo = gp.read_file("https://raw.githubusercontent.com/walkerke/geog30323/main/data/mexico.geojson")
import seaborn as sns
sns.set_theme(style = "white")
mxgeo.plot(column = "pri", cmap = "RdPu", figsize = (10, 8),
legend = True)
# Or, interactively:
mxgeo.explore(column = "pri", cmap = "RdPu",
tiles = "Esri.WorldGrayCanvas")import pandas as pd, seaborn as sns, matplotlib.pyplot as plt
sns.set_theme(style="whitegrid", font_scale = 1.3)
df = pd.read_csv("https://raw.githubusercontent.com/walkerke/geog30323/main/data/mexico.csv")
plt.figure(figsize = (10, 8))
p = sns.stripplot(data = df.sort_values('pri', ascending = False),
x = 'pri', y = 'name', palette = "RdPu",
orient = 'h', size = 8, hue = 'pri', legend = False)
p.set(xlabel = "% of workforce in primary sector",
xlim = (0, 35), ylabel = "")
p.axes.xaxis.grid(False)
p.axes.yaxis.grid(True)
sns.despine(left = True, bottom = True)We’ve discussed getting data from APIs to stream data in to your analysis session
pytidycensus: Python package to automate acquisition of US Census Bureau geographic data
Let’s try it out!
cook = tc.get_acs(geography = "tract", state = "IL", county = "Cook",
variables = {"median_income": "B19013_001"},
year = 2024, geometry = True)
cook["median_income"] = pd.to_numeric(cook["median_income"])
places = tc.get_acs(geography = "place", state = "IL", variables = "B01003_001",
year = 2024, geometry = True)
chicago = places.query('NAME == "Chicago city, Illinois"')
# Keep the Cook County tracts that fall inside Chicago's city limits
chi_tracts = cook[cook.representative_point().within(chicago.geometry.iloc[0])]has_starbucks
False 67986.0
True 106360.5
Name: median_income, dtype: float64
GEOG 30323 | Data Analysis & Visualization