Skip to content
Snippets Groups Projects
Commit 30319aff authored by sandcha's avatar sandcha
Browse files

Ajoute la lecture des dates d'effet typées et les explore

parent 969af802
No related branches found
No related tags found
1 merge request!6Explore l'ajout de dates de création de communes à partir de données de l'INSEE
%% Cell type:code id: tags:
``` python
from os import getcwd
from pandas import DataFrame, read_csv
from pandas import DataFrame, read_csv, to_datetime
```
%% Cell type:code id: tags:
``` python
# LISTE DES DONNEES
DATA_DIRECTORY = getcwd() + "/../../data/territoires/"
DATA_INSEE_MVTCOMMUNES_2024_PATH = DATA_DIRECTORY + "insee_mvtcommune_2024.csv" # INSEE COG 2024
```
%% Cell type:markdown id: tags:
### Dessin du fichier « Liste des évènements survenus aux communes, arrondissements municipaux, communes associées et communes déléguées depuis 1943 » et liste des variables
> Source (17/10/2024) : https://www.insee.fr/fr/information/7766585
| Nom de la variable | Longueur de la variable | Désignation et modalités de la variable |
| --- | --- | --- |
| MOD | 2 | Type d'évènement de communes |
| <span style='background-color:yellow'>DATE_EFF</span> | <span style='background-color:yellow'>10</span> | <span style='background-color:yellow'>Date d'effet (AAAA-MM-JJ)</span> |
| TYPECOM_AV | 4 | Type de la commune avant évènement |
| COM_AV | 5 | Code de la commune avant évènement |
| TNCC_AV | 1 | Type de nom en clair |
| NCC_AV | 200 | Nom en clair (majuscules) |
| NCCENR_AV | 200 | Nom en clair (typographie riche) |
| LIBELLE_AV | 200 | Nom en clair (typographie riche) avec article |
| TYPECOM_AP | 4 | Type de commune après l'évènement |
| <span style='background-color:yellow'>COM_AP</span> | <span style='background-color:yellow'>5</span> | <span style='background-color:yellow'>Code de la commune après l'évènement</span> |
| TNCC_AP | 1 | Type de nom en clair |
| NCC_AP | 200 | Nom en clair (majuscules) |
| NCCENR_AP | 200 | Nom en clair (typographie riche) |
| <span style='background-color:yellow'>LIBELLE_AP</span> | <span style='background-color:yellow'>200</span> | <span style='background-color:yellow'>Nom en clair (typographie riche) avec article</span> |
**Documentation complémentaire :**
« Commune » est à prendre dans un sens extensif comprenant aussi les arrondissements municipaux, communes associées et communes déléguées.
On peut avoir plusieurs lignes pour la transformation d’une même commune.
%% Cell type:markdown id: tags:
### Modalités pour le type d’événement
> Source (17/10/2024) : https://www.insee.fr/fr/information/7766169
| Type de modification | Code |
| --- | --- |
| Changement de nom | 10 |
| <span style='background-color:yellow'>Création</span> | <span style='background-color:yellow'>20</span> |
| Rétablissement | 21 |
| Suppression | 30 |
| Fusion simple | 31 |
| <span style='background-color:orange'>Création de commune nouvelle</span> | <span style='background-color:orange'>32</span> |
| Fusion association | 33 |
| Transformation de fusion association en fusion simple | 34 |
| Suppression de commune déléguée | 35 |
| Changement de code dû à un changement de département | 41 |
| Changement de code dû à un transfert de chef-lieu | 50 |
| Transformation de commune associée en commune déléguée | 70 |
| Rétablissement de commune déléguée | 71 |
➡️ Colonne `MOD`
%% Cell type:code id: tags:
``` python
# NCC_AV NCCENR_AV LIBELLE_AV
# NCC_AP NCCENR_AP LIBELLE_AP
insee_communes_2024: DataFrame=read_csv(
insee_mvtcommune_2024: DataFrame=read_csv(
DATA_INSEE_MVTCOMMUNES_2024_PATH,
dtype={
"NCC_AV": str,
"NCC_AP": str
},
encoding="utf-8",
sep=','
)
insee_communes_2024
insee_mvtcommune_2024.head()
```
%% Output
MOD DATE_EFF TYPECOM_AV COM_AV TNCC_AV NCC_AV \
0 10 2024-01-01 COM 04045 0.0 CERESTE
1 32 2024-01-01 COM 08053 0.0 BAZEILLES
2 32 2024-01-01 COM 08294 3.0 MONCELLE
3 32 2024-01-01 COM 08294 3.0 MONCELLE
4 32 2024-01-01 COM 16097 0.0 CHERVES RICHEMONT
NCCENR_AV LIBELLE_AV TYPECOM_AP COM_AP TNCC_AP \
0 Céreste Céreste COM 04045 0
1 Bazeilles Bazeilles COM 08053 0
2 Moncelle La Moncelle COM 08053 0
3 Moncelle La Moncelle COMD 08294 3
4 Cherves-Richemont Cherves-Richemont COMD 16097 0
NCC_AP NCCENR_AP LIBELLE_AP
0 CERESTE EN LUBERON Céreste-en-Luberon Céreste-en-Luberon
1 BAZEILLES Bazeilles Bazeilles
2 BAZEILLES Bazeilles Bazeilles
3 MONCELLE Moncelle La Moncelle
4 CHERVES RICHEMONT Cherves-Richemont Cherves-Richemont
%% Cell type:code id: tags:
``` python
DATE_FORMAT = "%Y-%m-%d"
date_eff = insee_mvtcommune_2024["DATE_EFF"]
date_eff_typed = to_datetime(date_eff, format=DATE_FORMAT) # dtype: datetime64[ns]
```
%% Cell type:code id: tags:
``` python
plus_ancien_evenement = date_eff_typed.min().strftime(DATE_FORMAT)
insee_mvtcommune_2024[date_eff == plus_ancien_evenement]
# Conclusion : Beauvais est la commune ayant la DATE_EFF la plus ancienne (1943-02-19)
```
%% Output
MOD DATE_EFF ... NCCENR_AP LIBELLE_AP
0 10 2024-01-01 ... Céreste-en-Luberon Céreste-en-Luberon
1 32 2024-01-01 ... Bazeilles Bazeilles
2 32 2024-01-01 ... Bazeilles Bazeilles
3 32 2024-01-01 ... Moncelle La Moncelle
4 32 2024-01-01 ... Cherves-Richemont Cherves-Richemont
... ... ... ... ... ...
13279 31 1943-02-19 ... Beauvais Beauvais
13280 31 1943-02-19 ... Beauvais Beauvais
13281 31 1943-02-19 ... Beauvais Beauvais
13282 31 1943-02-19 ... Beauvais Beauvais
13283 31 1943-02-19 ... Beauvais Beauvais
MOD DATE_EFF TYPECOM_AV COM_AV TNCC_AV NCC_AV \
13279 31 1943-02-19 COM 60057 0.0 BEAUVAIS
13280 31 1943-02-19 COM 60384 0.0 MARISSEL
13281 31 1943-02-19 COM 60467 0.0 NOTRE DAME DU THIL
13282 31 1943-02-19 COM 60580 0.0 SAINT JUST DES MARAIS
13283 31 1943-02-19 COM 60696 0.0 VOISINLIEU
NCCENR_AV LIBELLE_AV TYPECOM_AP COM_AP \
13279 Beauvais Beauvais COM 60057
13280 Marissel Marissel COM 60057
13281 Notre-Dame-du-Thil Notre-Dame-du-Thil COM 60057
13282 Saint-Just-des-Marais Saint-Just-des-Marais COM 60057
13283 Voisinlieu Voisinlieu COM 60057
[13284 rows x 14 columns]
TNCC_AP NCC_AP NCCENR_AP LIBELLE_AP
13279 0 BEAUVAIS Beauvais Beauvais
13280 0 BEAUVAIS Beauvais Beauvais
13281 0 BEAUVAIS Beauvais Beauvais
13282 0 BEAUVAIS Beauvais Beauvais
13283 0 BEAUVAIS Beauvais Beauvais
%% Cell type:code id: tags:
``` python
CODE_INSEE_BEAUVAIS = "60057" # inchangé pour le coeur de Beauvais, avant et après évènement(s)
filtre_bauvais = (insee_mvtcommune_2024["COM_AV"] == CODE_INSEE_BEAUVAIS) | (insee_mvtcommune_2024["COM_AP"] == CODE_INSEE_BEAUVAIS)
insee_mvtcommune_2024[filtre_bauvais]
# Conclusion : la commune ayant la date la plus ancienne a pour évènements des fusions (pas de création de commune)
```
%% Output
MOD DATE_EFF TYPECOM_AV COM_AV TNCC_AV NCC_AV \
13279 31 1943-02-19 COM 60057 0.0 BEAUVAIS
13280 31 1943-02-19 COM 60384 0.0 MARISSEL
13281 31 1943-02-19 COM 60467 0.0 NOTRE DAME DU THIL
13282 31 1943-02-19 COM 60580 0.0 SAINT JUST DES MARAIS
13283 31 1943-02-19 COM 60696 0.0 VOISINLIEU
NCCENR_AV LIBELLE_AV TYPECOM_AP COM_AP \
13279 Beauvais Beauvais COM 60057
13280 Marissel Marissel COM 60057
13281 Notre-Dame-du-Thil Notre-Dame-du-Thil COM 60057
13282 Saint-Just-des-Marais Saint-Just-des-Marais COM 60057
13283 Voisinlieu Voisinlieu COM 60057
TNCC_AP NCC_AP NCCENR_AP LIBELLE_AP
13279 0 BEAUVAIS Beauvais Beauvais
13280 0 BEAUVAIS Beauvais Beauvais
13281 0 BEAUVAIS Beauvais Beauvais
13282 0 BEAUVAIS Beauvais Beauvais
13283 0 BEAUVAIS Beauvais Beauvais
%% Cell type:code id: tags:
``` python
est_commune_nouvelle = insee_mvtcommune_2024["MOD"] == 32
communes_nouvelles = insee_mvtcommune_2024[est_commune_nouvelle]
communes_nouvelles["DATE_EFF"].min()
# Conclusion : l'évènement "Création decommune nouvelle" a pour plus ancienne date référencée le '2012-01-01'
```
%% Output
'2012-01-01'
%% Cell type:code id: tags:
``` python
est_creation_commune = insee_mvtcommune_2024["MOD"] == 20
creation_commune = insee_mvtcommune_2024[est_creation_commune]
creation_commune["DATE_EFF"].min()
# Conclusion : l'évènement "Création" a pour plus ancienne date référencée le '1945-09-17'
```
%% Output
'1945-09-17'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment