Goal
Use GTD-like incident data to:
- Visualize incidents over time
- Compare regions
- Identify major trend changes
Important note
This is a sensitive dataset. Focus on high-level aggregated analysis and avoid sensationalizing.
Analysis pipeline
flowchart LR A["Raw incidents"] --> B["Aggregate
(by year, region)"] B --> C["Visualize
(trend line, top regions)"] C --> D["Caveat
(missing/reporting bias)"] D --> E["Conclude
(high-level summary)"]
Step 1: Load
import pandas as pd
df = pd.read_csv("data/gtd.csv")
print(df.head())Step 2: Incidents by year
import matplotlib.pyplot as plt
yearly = df.groupby("year").size()
plt.figure(figsize=(10, 4))
plt.plot(yearly.index, yearly.values)
plt.title("Incidents by year")
plt.xlabel("Year")
plt.ylabel("Count")
plt.tight_layout()
plt.show()Step 3: Compare regions
import seaborn as sns
import matplotlib.pyplot as plt
regions = df["region"].value_counts().head(10).reset_index()
regions.columns = ["region", "count"]
plt.figure(figsize=(10, 4))
sns.barplot(data=regions, x="count", y="region")
plt.title("Top regions by incident count")
plt.tight_layout()
plt.show()Visualize it
Deliverable
- Overall trend
- Top regions by incidents
- Notes about missingness/reporting bias
Check your understanding
What scope does the lesson recommend for this sensitive dataset?
The project stresses aggregated analysis and responsible framing.
Show answer
A — High-level aggregated analysis, avoiding sensationalizing — The project stresses aggregated analysis and responsible framing.
How are incidents per year computed?
Grouping by year and counting rows gives incidents per year.
Show answer
A — df.groupby("year").size() — Grouping by year and counting rows gives incidents per year.
A region shows few incidents. Why is it not necessarily safer?
Reporting bias and missingness should be noted in the chart caption.
Show answer
A — It may be under-recorded because of sparse or inconsistent reporting — Reporting bias and missingness should be noted in the chart caption.
How does the project pick the top regions?
Counting rows per region and keeping the ten largest gives a readable ranking.
Show answer
A — value_counts().head(10) on region, shown in a horizontal bar plot — Counting rows per region and keeping the ten largest gives a readable ranking.
🧪 Try It Yourself
Exercise 1 – Incidents per year
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 2 – Top regions by incident count
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.Exercise 3 – Bucket missing region as "Unknown"
Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.
Press Run to see what your code prints.