Python Central HubSign in

Data Analytics with Python / Phase 10: Data Analytics Projects

Global Terrorism Database Analysis

Analyze incidents by year/region, visualize trends, and summarize patterns responsibly.

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

diagram GTD trend analysis pipeline mermaid
From raw incident records to a responsible, aggregated summary.

Step 1: Load

Python
import pandas as pd
 
df = pd.read_csv("data/gtd.csv")
print(df.head())

Step 2: Incidents by year

Python
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

Python
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

sketch Incidents by year p5.js
A single amber line shows the overall trend across years; annotate any sharp turns.

Deliverable

  • Overall trend
  • Top regions by incidents
  • Notes about missingness/reporting bias

Check your understanding

quizCheck yourself
  1. What scope does the lesson recommend for this sensitive dataset?

    Show answer

    A — High-level aggregated analysis, avoiding sensationalizing — The project stresses aggregated analysis and responsible framing.

  2. How are incidents per year computed?

    Show answer

    A — df.groupby("year").size() — Grouping by year and counting rows gives incidents per year.

  3. A region shows few incidents. Why is it not necessarily safer?

    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.

  4. How does the project pick the top regions?

    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

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Top regions by incident count

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Bucket missing region as "Unknown"

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did