-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_rapport.py
More file actions
55 lines (44 loc) · 1.96 KB
/
Copy path03_rapport.py
File metadata and controls
55 lines (44 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Génération d'un rapport mensuel : évolution nationale des demandeurs
d'emploi (catégorie A), toutes régions, 24 derniers mois.
"""
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
SRC = "data/dares_defm_clean.parquet"
def generer_rapport():
df = pd.read_parquet(SRC)
national = df[
(df["region"] == "France") | (df["code_region"] == "Total")
]
if national.empty: # fallback : somme des régions si pas de ligne "France"
national = (
df[(df["categorie"] == "A") & (df["sexe"] == "Total")
& (df["tranche_age"] == "Total") & (df["anciennete"] == "Total")]
.groupby("date")["nb_demandeurs"].sum().reset_index()
)
else:
national = national[
(national["categorie"] == "A") & (national["sexe"] == "Total")
& (national["tranche_age"] == "Total") & (national["anciennete"] == "Total")
][["date", "nb_demandeurs"]]
national = national.sort_values("date").tail(24)
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(national["date"], national["nb_demandeurs"], marker="o", markersize=3)
ax.set_title("Demandeurs d'emploi catégorie A, 24 derniers mois (CVS-CJO)")
ax.set_ylabel("Nombre de demandeurs d'emploi")
ax.grid(alpha=0.3)
plt.tight_layout()
plt.savefig("rapports/evolution_categorie_A.png", dpi=120)
plt.close()
dernier = national.iloc[-1]
precedent = national.iloc[-2]
variation = (dernier["nb_demandeurs"] / precedent["nb_demandeurs"] - 1) * 100
with open("rapports/synthese.txt", "w") as f:
f.write(f"Rapport généré pour {dernier['date'].strftime('%Y-%m')}\n")
f.write(f"Demandeurs d'emploi catégorie A : {dernier['nb_demandeurs']:,.0f}\n")
f.write(f"Variation vs mois précédent : {variation:+.2f}%\n")
print(f"Rapport généré : {dernier['nb_demandeurs']:,.0f} ({variation:+.2f}%)")
if __name__ == "__main__":
generer_rapport()