-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.qmd
175 lines (133 loc) · 4.66 KB
/
index.qmd
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
title: "Public civil servant and inflation rate in France"
---
In the file [fonctionnaires_pauvres.py](fonctionnaires_pauvres.py) we investigated the evolution of the salary of civil servants in France through the "Point d'indice" evolution.
```{python}
#| echo: false
#| warning: false
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
# import seaborn as sns
# import matplotlib.pylab as plt
import numpy as np
import pooch
import zipfile
#| echo: false
import datetime
from dateutil.relativedelta import relativedelta
# Source: # https://www.insee.fr/fr/statistiques/serie/001763852
current_time = datetime.datetime.now()
last_date = current_time - relativedelta(months=2)
fname_inflation = pooch.retrieve(f"https://www.insee.fr/fr/statistiques/serie/telecharger/csv/001763852?ordre=antechronologique&transposition=donneescolonne&periodeDebut=1&anneeDebut=1990&periodeFin={last_date.month}&anneeFin={last_date.year}&revision=sansrevisions", known_hash=None)
zf = zipfile.ZipFile(fname_inflation)
# Open a subdirectory where the 'valeurs_mensuelles.csv file is located
for file in zf.namelist():
if 'valeurs_mensuelles.csv' in file:
with zf.open(file, 'r') as f:
df_ipc = pd.read_csv(f, header=0, sep=";",skiprows=4)
break
```
```{python}
#| echo: false
#| layout-ncol: 1
df_ipc.columns = ["Date", "IPC", "Useless", "Date2"]
df_ipc.index = pd.to_datetime(df_ipc["Date"], format="%Y-%m")
df_ipc.drop(df_ipc.columns[[0, 2]], inplace=True, axis=1)
df_ipc.head()
# Set origin
init_date = "2005-09-01"
df_ipc["IPC(idx)"] = df_ipc["IPC"] / df_ipc.loc[init_date]["IPC"]
df_ipc.head()
# Sort by "Date" in ascending order
df_ipc.sort_values(by="Date", inplace=True)
```
```{python}
#| echo: false
#| warning: false
fname_pt_indice = pooch.retrieve("https://www.data.gouv.fr/fr/datasets/r/6b5a3e7e-7de7-437c-b8eb-a04ab4138fbb", known_hash=None)
df_pt_idx = pd.read_csv(fname_pt_indice, usecols=["date_effet", "valeur_100_points_euros"])
df_pt_idx = df_pt_idx.rename(columns={"date_effet": "Date", "valeur_100_points_euros": "Point d'indice"})
df_pt_idx["Date"] = pd.to_datetime(df_pt_idx["Date"], format="%Y-%m-%d")
df_pt_idx.sort_values(by="Date", inplace=True)
df = pd.merge_asof(df_ipc, df_pt_idx, on="Date")
df.index = df["Date"]
df.loc[init_date]["Point d'indice"]
df["Point d'indice(idx)"] = (
df["Point d'indice"] / df.loc[init_date]["Point d'indice"]
)
df["Point d'indice(euros constant)"] = (
df["Point d'indice(idx)"] / df["IPC(idx)"]
)
```
```{python}
#| echo: false
#| layout-ncol: 1
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Date"], y=df["IPC(idx)"], mode='lines', name='IPC(idx)'))
fig.add_trace(go.Scatter(x=df["Date"], y=df["Point d'indice(idx)"], mode='lines', name="Point d'indice(idx)"))
fig.update_layout(
# style white:
template="simple_white",
title="Joint evolution of inflation and point d'indice <br> Réference 1 le " + init_date,
xaxis=dict(
range=[init_date, df['Date'].iloc[-1]],
tickangle=-60,
nticks=15,
tickformat='%Y'
),
hovermode="x unified",
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.01
)
)
fig.update_traces(hovertemplate="%{x|%Y/%m} value: %{y}")
```
```{python}
#| echo: false
#| layout-ncol: 1
fig = go.Figure()
fig.add_trace(go.Scatter(x=df["Date"], y=df["Point d'indice(euros constant)"], mode='lines', name="Point d'indice(euros constant)"))
fig.update_layout(
template="simple_white",
title="Point d'indice (corrigé de l'inflation): <br> Réference 1 le " + init_date,
xaxis=dict(
range=[init_date, df['Date'].iloc[-1]],
tickangle=-60,
nticks=15,
tickformat='%Y'
),
yaxis=dict(
range=[0.80, 1.2]
),
hovermode="x unified",
legend=dict(
yanchor="top",
y=0.9,
xanchor="left",
x=0.1
)
)
fig.update_traces(hovertemplate="%{x|%Y/%m} value: %{y}")
# matplotlib version
# df.plot(
# x="Date",
# y=["Point d'indice(euros constant)"],
# title="Point d'indice (€ corrigé de l'inflation):\n Réference 1 le "
# + init_date,
# )
# ax = plt.gca()
# ax.set_xlim(left=np.datetime64(init_date))
# ax.set_ylim(bottom=0.80, top=1.2)
# ax.legend().remove()
```
```{python}
#| echo: false
print(f"Computation was performed at : {current_time} (GMT)")
```
Sources are:
- inflation : [https://www.insee.fr/fr/statistiques/serie/001763852#Telechargement](https://www.insee.fr/fr/statistiques/serie/001763852#Telechargement)
- point d'indice: [https://www.data.gouv.fr/fr/datasets/r/6b5a3e7e-7de7-437c-b8eb-a04ab4138fbb](https://www.data.gouv.fr/fr/datasets/r/6b5a3e7e-7de7-437c-b8eb-a04ab4138fbb)