| """One-shot analysis + visualisation of the CNIL sanctions dataset. |
| |
| Produces: |
| - charts/yearly_volume.png |
| - charts/yearly_fines.png |
| - charts/sector_breakdown.png |
| - charts/breach_themes.png |
| - charts/fine_buckets.png |
| - charts/simplified_share.png |
| - insights.json (machine-readable headline numbers for the README) |
| """ |
| from __future__ import annotations |
|
|
| import json |
| from collections import Counter |
| from pathlib import Path |
|
|
| import matplotlib |
|
|
| matplotlib.use("Agg") |
| import matplotlib.pyplot as plt |
| import pandas as pd |
|
|
| HERE = Path(__file__).parent |
| PARQUET = HERE / "cnil_sanctions_analysis.parquet" |
| CHARTS = HERE / "charts" |
| CHARTS.mkdir(exist_ok=True) |
|
|
| |
| plt.rcParams.update({ |
| "figure.dpi": 130, |
| "savefig.dpi": 130, |
| "savefig.bbox": "tight", |
| "font.family": "DejaVu Sans", |
| "axes.spines.top": False, |
| "axes.spines.right": False, |
| "axes.grid": True, |
| "axes.grid.axis": "y", |
| "grid.color": "#e5e7eb", |
| "grid.linestyle": "-", |
| "grid.linewidth": 0.8, |
| "axes.titlesize": 14, |
| "axes.titleweight": "bold", |
| "axes.labelsize": 11, |
| }) |
|
|
| ACCENT = "#2563eb" |
| ACCENT_2 = "#dc2626" |
| NEUTRAL = "#6b7280" |
|
|
| df = pd.read_parquet(PARQUET) |
| print(f"loaded {len(df)} rows, {len(df.columns)} cols") |
|
|
| |
| yearly = df["n_sanction_year"].dropna().astype(int).value_counts().sort_index() |
| yearly_simplified = ( |
| df[df["is_simplified_procedure"] == True]["n_sanction_year"] |
| .dropna() |
| .astype(int) |
| .value_counts() |
| .reindex(yearly.index, fill_value=0) |
| ) |
| yearly_standard = yearly - yearly_simplified |
|
|
| fig, ax = plt.subplots(figsize=(10, 5)) |
| ax.bar(yearly.index, yearly_standard, color=ACCENT, label="standard / unspecified procedure") |
| ax.bar(yearly.index, yearly_simplified, bottom=yearly_standard, color=ACCENT_2, label="simplified procedure") |
| ax.set_title("CNIL sanctions per year, by procedure type (2011 – 2025)") |
| ax.set_xlabel("Year") |
| ax.set_ylabel("Number of sanctions") |
| ax.set_xticks(yearly.index) |
| ax.legend(frameon=False, loc="upper left") |
| for x, y in zip(yearly.index, yearly.values): |
| ax.text(x, y + 1, str(int(y)), ha="center", va="bottom", fontsize=8, color=NEUTRAL) |
| fig.savefig(CHARTS / "yearly_volume.png") |
| plt.close(fig) |
| print(" ✓ yearly_volume.png") |
|
|
| |
| df_fines = df.dropna(subset=["amount_fine_eur", "n_sanction_year"]).copy() |
| df_fines["n_sanction_year"] = df_fines["n_sanction_year"].astype(int) |
| fines_per_year = df_fines.groupby("n_sanction_year")["amount_fine_eur"].sum() / 1e6 |
| fines_per_year = fines_per_year.reindex(yearly.index, fill_value=0.0) |
| fines_count = df_fines.groupby("n_sanction_year").size().reindex(yearly.index, fill_value=0) |
|
|
| fig, ax = plt.subplots(figsize=(10, 5)) |
| ax.bar(fines_per_year.index, fines_per_year.values, color=ACCENT) |
| ax.set_title("Aggregate disclosed fines per year (€M)") |
| ax.set_xlabel("Year") |
| ax.set_ylabel("Fines (€ millions)") |
| ax.set_xticks(fines_per_year.index) |
| for x, y, c in zip(fines_per_year.index, fines_per_year.values, fines_count.values): |
| if y > 0: |
| ax.text(x, y + 5, f"€{y:.0f}M\n(n={c})", ha="center", va="bottom", |
| fontsize=8, color=NEUTRAL) |
| fig.savefig(CHARTS / "yearly_fines.png") |
| plt.close(fig) |
| print(" ✓ yearly_fines.png") |
|
|
| |
| sec = df["cat_sector_group"].dropna().value_counts() |
| labels_map = { |
| "private_company": "Private company", |
| "public": "Public sector", |
| "professional_individual": "Professional individual", |
| "association": "Association", |
| "political": "Political party", |
| "other": "Other", |
| } |
| sec = sec.rename(index=lambda x: labels_map.get(x, x)) |
|
|
| fig, ax = plt.subplots(figsize=(8, 5)) |
| bars = ax.barh(sec.index[::-1], sec.values[::-1], color=ACCENT) |
| ax.set_title("Sanctions by sector (2011 – 2025)") |
| ax.set_xlabel("Number of sanctions") |
| ax.grid(axis="y", visible=False) |
| ax.grid(axis="x", visible=True) |
| for bar, val in zip(bars, sec.values[::-1]): |
| ax.text(val + 3, bar.get_y() + bar.get_height() / 2, |
| f"{val} ({val / sec.sum():.0%})", |
| va="center", fontsize=9, color=NEUTRAL) |
| fig.savefig(CHARTS / "sector_breakdown.png") |
| plt.close(fig) |
| print(" ✓ sector_breakdown.png") |
|
|
| |
| breach_cols = [c for c in df.columns if c.startswith("is_breach_") or c == "is_involves_sensitive_data"] |
| breach_counts = {c: int(df[c].fillna(False).sum()) for c in breach_cols} |
| breach_counts = dict(sorted(breach_counts.items(), key=lambda kv: kv[1])) |
| pretty = { |
| "is_breach_security": "Security of processing (Art. 32)", |
| "is_breach_transparency": "Information / transparency", |
| "is_breach_consent": "Lawful basis: consent", |
| "is_breach_data_rights": "Rights of data subjects", |
| "is_breach_cookies": "Cookies / trackers (Art. 82)", |
| "is_breach_minimization": "Data minimisation", |
| "is_breach_processor": "Sub-processor obligations", |
| "is_involves_sensitive_data": "Special-category data (Art. 9)", |
| } |
| labels = [pretty.get(c, c) for c in breach_counts] |
| vals = list(breach_counts.values()) |
|
|
| fig, ax = plt.subplots(figsize=(9, 5)) |
| bars = ax.barh(labels, vals, color=ACCENT) |
| ax.set_title("Breach themes detected across CNIL sanctions") |
| ax.set_xlabel(f"# of decisions mentioning this theme (n={len(df)})") |
| ax.grid(axis="y", visible=False) |
| ax.grid(axis="x", visible=True) |
| for bar, v in zip(bars, vals): |
| ax.text(v + 2, bar.get_y() + bar.get_height() / 2, |
| f"{v} ({v / len(df):.0%})", |
| va="center", fontsize=9, color=NEUTRAL) |
| fig.savefig(CHARTS / "breach_themes.png") |
| plt.close(fig) |
| print(" ✓ breach_themes.png") |
|
|
| |
| fb = df["cat_fine_bucket"].dropna().value_counts() |
| order = ["none", "under_10k", "under_100k", "under_1m", "over_1m"] |
| fb = fb.reindex([o for o in order if o in fb.index], fill_value=0) |
| label_order = { |
| "none": "no fine", |
| "under_10k": "< €10 k", |
| "under_100k": "€10 k – 100 k", |
| "under_1m": "€100 k – 1 M", |
| "over_1m": "> €1 M", |
| } |
| fb = fb.rename(index=label_order) |
|
|
| fig, ax = plt.subplots(figsize=(8, 5)) |
| ax.bar(fb.index, fb.values, color=ACCENT) |
| ax.set_title("Fine-size distribution") |
| ax.set_xlabel("Fine bucket") |
| ax.set_ylabel("Number of sanctions") |
| for i, (idx, v) in enumerate(fb.items()): |
| ax.text(i, v + 1, str(int(v)), ha="center", va="bottom", fontsize=9, color=NEUTRAL) |
| fig.savefig(CHARTS / "fine_buckets.png") |
| plt.close(fig) |
| print(" ✓ fine_buckets.png") |
|
|
| |
| simp_share = (yearly_simplified / yearly.replace(0, 1)).fillna(0) * 100 |
|
|
| fig, ax = plt.subplots(figsize=(10, 4.5)) |
| ax.plot(simp_share.index, simp_share.values, color=ACCENT_2, marker="o", linewidth=2) |
| ax.fill_between(simp_share.index, 0, simp_share.values, color=ACCENT_2, alpha=0.15) |
| ax.set_title("Share of sanctions issued under the SIMPLIFIED procedure") |
| ax.set_xlabel("Year") |
| ax.set_ylabel("% of yearly sanctions") |
| ax.set_xticks(simp_share.index) |
| ax.set_ylim(0, 100) |
| for x, y in zip(simp_share.index, simp_share.values): |
| if y > 0: |
| ax.text(x, y + 2, f"{y:.0f}%", ha="center", fontsize=8, color=NEUTRAL) |
| fig.savefig(CHARTS / "simplified_share.png") |
| plt.close(fig) |
| print(" ✓ simplified_share.png") |
|
|
| |
| fines_clean = df["amount_fine_eur"].dropna() |
| top_fines = ( |
| df.dropna(subset=["amount_fine_eur"]) |
| .sort_values("amount_fine_eur", ascending=False) |
| .head(10)[["dn_sanction", "organism_type_raw", "amount_fine_eur", "main_breaches_raw"]] |
| .to_dict(orient="records") |
| ) |
|
|
| insights = { |
| "n_rows": int(len(df)), |
| "years": [int(df["n_sanction_year"].min()), int(df["n_sanction_year"].max())], |
| "growth_2014_to_2024": round(yearly.get(2024, 0) / max(1, yearly.get(2014, 1)), 1), |
| "growth_2022_to_2024": round(yearly.get(2024, 0) / max(1, yearly.get(2022, 1)), 1), |
| "private_share_pct": round( |
| 100 * (df["cat_sector_group"] == "private_company").sum() / len(df), 1 |
| ), |
| "simplified_share_total_pct": round( |
| 100 * (df["is_simplified_procedure"] == True).sum() |
| / max(1, df["is_simplified_procedure"].notna().sum()), |
| 1, |
| ), |
| "simplified_share_2024_pct": round(simp_share.get(2024, 0.0), 1), |
| "fines_reported": int(fines_clean.shape[0]), |
| "total_fines_meur": round(fines_clean.sum() / 1e6, 1), |
| "median_fine_eur": float(fines_clean.median()) if len(fines_clean) else 0.0, |
| "max_fine_eur": float(fines_clean.max()) if len(fines_clean) else 0.0, |
| "top_breach_theme": max(breach_counts, key=breach_counts.get), |
| "top_breach_count": max(breach_counts.values()), |
| "top_fines": top_fines, |
| } |
| (HERE / "insights.json").write_text( |
| json.dumps(insights, indent=2, ensure_ascii=False, default=str) |
| ) |
| print("\ninsights:", json.dumps(insights, indent=2, ensure_ascii=False, default=str)) |
|
|