Skip to content
Snippets Groups Projects
Commit 8ca7392e authored by sandcha's avatar sandcha
Browse files

Ajoute la comparaison notifié calculé pour une commune en 2024

parent e14872cf
No related branches found
No related tags found
1 merge request!7Ajoute un notebook d'analyse d'une unique commune configurable pour 2024
%% Cell type:markdown id: tags:
# Analyse des critères et dotations d'une commune
%% Cell type:code id: tags:
``` python
YEAR = 2024
CODE_INSEE_COMMUNE = "01317" # code postal = "01250"
NOM_COMMUNE = "Ramasse"
```
%% Cell type:markdown id: tags:
## Données brutes
%% Cell type:code id: tags:
``` python
# Activate multi-output in notebook
# %matplotlib inline (pour des graphes)
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
```
%% Cell type:code id: tags:
``` python
import logging
from leximpact_dotations_back import logger
logger.setLevel(logging.INFO)
```
%% Cell type:code id: tags:
``` python
from os import getcwd
from os.path import join
from leximpact_dotations_back.data_building.build_dotations_data import load_criteres
DATA_DIRECTORY = join(getcwd(), "..", "..", "data")
data_criteres = load_criteres(DATA_DIRECTORY, YEAR)
data_brutes_criteres = load_criteres(DATA_DIRECTORY, YEAR)
# data_criteres.columns
data_criteres.columns[data_criteres.columns.str.contains("rurale")]
# data_brutes_criteres.columns
# data_brutes_criteres.columns[data_brutes_criteres.columns.str.contains("rurale")]
```
%% Output
🔹 INFO
Loading /Users/sch/dev/gitruc/data-exploration/data/criteres_repartition_2024.csv...
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:50: DtypeWarning: Columns (2,19,25,26,35,36,38,42,44,51,57,59,63,64,77,105,119,120,121,122,135,137,138,139,145,147,148,154,159) have mixed types. Specify dtype option on import or set low_memory=False.
dgcl_data = read_csv(csv_path, decimal=DECIMAL_SEPARATOR_2024, dtype={CODE_INSEE_2024: CODE_INSEE_DTYPE_2024})
Index(['Dotation de solidarité rurale - Fraction bourg-centre - Montant de la commune éligible',
'Dotation de solidarité rurale - Fraction bourg-centre - Montant de la garantie de sortie BC',
'Dotation de solidarité rurale - Fraction bourg-centre - Montant global réparti',
'Dotation de solidarité rurale - Fraction bourg-centre - Population DGF plafonnée',
'Dotation de solidarité rurale - Fraction bourg-centre - Population DGF des communes du canton d'appartenance en 2014',
'Dotation de solidarité rurale - Fraction bourg-centre - Pourcentage de la population communale dans le canton d'appartenance en 2014',
'Dotation de solidarité rurale - Fraction bourg-centre - Population DGF des communes de l'unité urbaine',
'Dotation de solidarité rurale - Fraction bourg-centre - Population départementale de référence de l'unité urbaine',
'Dotation de solidarité rurale - Fraction bourg-centre - La commune appartient à une UU avec un CL de département ?',
'Dotation de solidarité rurale - Fraction bourg-centre - Code commune chef-lieu de canton au 1er janvier 2014',
'Dotation de solidarité rurale - Fraction bourg-centre - Nom commune chef-lieu de canton au 1er janvier 2014',
'Dotation de solidarité rurale - Fraction bourg-centre - Bureaux centralisateurs',
'Dotation de solidarité rurale - Fraction bourg-centre - Chef-lieu d'arrondissement au 31 décembre 2014',
'Dotation de solidarité rurale - Fraction bourg-centre - Commune située en ZRR',
'Dotation de solidarité rurale - Fraction bourg-centre - Grille de densité de l'INSEE',
'Dotation de solidarité rurale - Fraction péréquation - Part Pfi',
'Dotation de solidarité rurale - Fraction péréquation - Part VOIRIE',
'Dotation de solidarité rurale - Fraction péréquation - Part ENFANTS',
'Dotation de solidarité rurale - Fraction péréquation - Part Pfi/hectare',
'Dotation de solidarité rurale - Fraction péréquation - Commune éligible',
'Dotation de solidarité rurale - Fraction péréquation - Montant global réparti',
'Dotation de solidarité rurale - Fraction péréquation - Commune située en zone de montagne',
'Dotation de solidarité rurale - Fraction péréquation - Commune insulaire',
'Dotation de solidarité rurale - Fraction péréquation - Population 3 à 16 ans',
'Dotation de solidarité rurale - Fraction péréquation - Longueur de voirie en mètres',
'Dotation de solidarité rurale - Fraction cible - Revenu imposable moyen par habitant sur 3 ans',
'Dotation de solidarité rurale - Fraction cible - Indice synthétique DSR Cible',
'Dotation de solidarité rurale - Fraction cible - Rang DSR Cible',
'Dotation de solidarité rurale - Fraction cible - Commune éligible',
'Dotation de solidarité rurale - Fraction cible - Part Pfi',
'Dotation de solidarité rurale - Fraction cible - Part VOIRIE',
'Dotation de solidarité rurale - Fraction cible - Part ENFANTS',
'Dotation de solidarité rurale - Fraction cible - Part Pfi/hectare (Pfis)',
'Dotation de solidarité rurale - Fraction cible - Montant de la garantie de sortie cible des communes devenues inéligibles en N',
'Dotation de solidarité rurale - Fraction cible - Montant global réparti',
'Dotation de solidarité rurale - Montant total réparti'],
dtype='object')
%% Cell type:code id: tags:
``` python
def get_commune_in_data_criteres():
filter_code_insee = data_criteres['Informations générales - Code INSEE de la commune'] == CODE_INSEE_COMMUNE
commune_in_data = data_criteres[filter_code_insee]
def get_commune_in_data_criteres(data_brutes_criteres, code_insee_commune):
filter_code_insee = data_brutes_criteres['Informations générales - Code INSEE de la commune'] == code_insee_commune
commune_in_data = data_brutes_criteres[filter_code_insee]
return commune_in_data
commune_in_data = get_commune_in_data_criteres()
commune_in_data = get_commune_in_data_criteres(data_criteres, CODE_INSEE_COMMUNE)
commune_in_data
```
%% Output
Informations générales - Code INSEE de la commune \
267 01317
Informations générales - Nom de la commune \
267 RAMASSE
Informations générales - Code département de la commune \
267 1
Informations générales - Code SIREN de l'EPCI \
267 200071751
Informations générales - Nom de l'EPCI Informations générales - Exercice \
267 CA DU BASSIN DE BOURG-EN-BRESSE 2024
Informations générales - Régime fiscal de l'EPCI N \
267 FPU
Informations générales - Population DGF de l'année N \
267 348
Informations générales - Population INSEE de l'année N \
267 337
Informations générales - Résidences secondaires de l'année N ... \
267 11 ...
Dotation d’aménagement des communes et circonscriptions territoriales d’outre-mer - Coefficient de majoration de l'IS \
267 n.c
Dotation d’aménagement des communes et circonscriptions territoriales d’outre-mer - Potentiel financier majoré de l'octroi de mer \
267 n.c
Dotation d’aménagement des communes et circonscriptions territoriales d’outre-mer - Potentiel financier majoré de l'octroi de mer par habitant \
267 n.c
Dotation d’aménagement des communes et circonscriptions territoriales d’outre-mer - Nombre de foyers bénéficiaires du RSA \
267 n.c
Dotation en faveur des communes nouvelles - Commune éligible à la part de garantie \
267 0
Dotation en faveur des communes nouvelles - DGF de référence de la commune nouvelle \
267 0
Dotation en faveur des communes nouvelles - Montant de la part garantie \
267 0
Dotation en faveur des communes nouvelles - Commune éligible à la part d'amorçage \
267 0
Dotation en faveur des communes nouvelles - Montant de la part d'amorçage \
267 0
Dotation en faveur des communes nouvelles - Montant total réparti
267 0
[1 rows x 180 columns]
%% Cell type:markdown id: tags:
### Dotations de la commune dans les données brutes
%% Cell type:code id: tags:
``` python
# from leximpact_dotations_back.mapping.criteres_dgcl_2024 import montants_dotations_2024
# montants_dotations_2024
print(f"[🧳 DF] {commune_in_data['Dotation forfaitaire - Dotation forfaitaire notifiée N'].values[0]}")
print(f"[🌻 DSR] {commune_in_data['Dotation de solidarité rurale - Montant total réparti'].values[0]}")
print(f"[🏢 DSU] {commune_in_data['Dotation de solidarité urbaine et de cohésion sociale - Montant total réparti'].values[0]}")
DGCL_VALUE__STRING_NON_BREAKING_SPACE = '\xa0'
def format_string_numeric_with_spaces_to_numeric(string_numeric):
clean_value = string_numeric
is_float = "," in string_numeric
if is_float:
clean_value = string_numeric.replace(',', '.')
clean_value = clean_value.replace(DGCL_VALUE__STRING_NON_BREAKING_SPACE, "")
return float(clean_value) if is_float else int(clean_value)
df_notifiee_2024 = format_string_numeric_with_spaces_to_numeric(commune_in_data['Dotation forfaitaire - Dotation forfaitaire notifiée N'].values[0])
dsr_notifiee_2024 = format_string_numeric_with_spaces_to_numeric(commune_in_data['Dotation de solidarité rurale - Montant total réparti'].values[0])
dsu_notifiee_2024 = format_string_numeric_with_spaces_to_numeric(commune_in_data['Dotation de solidarité urbaine et de cohésion sociale - Montant total réparti'].values[0])
print(f"[🧳 DF] Notifiée : {df_notifiee_2024}")
print(f"[🌻 DSR] Notifiée : {dsr_notifiee_2024}")
print(f"[🏢 DSU] Notifiée : {dsu_notifiee_2024}")
```
%% Output
[🧳 DF] Notifiée : 15288
[🌻 DSR] Notifiée : 10783
[🏢 DSU] Notifiée : 0
%% Cell type:markdown id: tags:
### Dotations de la commune dans les données calculées par leximpact-dotations-back
%% Cell type:code id: tags:
``` python
# Option 1) from leximpact_dotations_back.preload import dotations_adapted_criteres_2024, simulation_2024
## Option 2)
## from pandas import DataFrame
## from leximpact_dotations_back.computing.simulation_2024 import build_data_2024, get_simulation_2024
## (oui, on charge les données une seconde fois ici)
## dotations_adapted_criteres_2024: DataFrame = build_data_2024(data_directory = DATA_DIRECTORY, year = YEAR)
### Option 3) pour vérification rapide sans contraintes de chemins de données
from data_exploration.utils.simulation_2024 import buid_data_2023_for_2024, build_data_2024, create_simulation_2024
dotations_adapted_criteres_2024 = build_data_2024()
selection_data_2023 = buid_data_2023_for_2024()
simulation_2024 = create_simulation_2024(dotations_adapted_criteres_2024, selection_data_2023)
```
%% Output
🔹 INFO
Loading /Users/sch/dev/gitruc/data-exploration/data/criteres_repartition_2024.csv...
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:50: DtypeWarning: Columns (2,19,25,26,35,36,38,42,44,51,57,59,63,64,77,105,119,120,121,122,135,137,138,139,145,147,148,154,159) have mixed types. Specify dtype option on import or set low_memory=False.
dgcl_data = read_csv(csv_path, decimal=DECIMAL_SEPARATOR_2024, dtype={CODE_INSEE_2024: CODE_INSEE_DTYPE_2024})
🔸 WARNING
Specific treatment applied to some communes: 57163 and 87116
🔹 INFO
Loading /Users/sch/dev/gitruc/data-exploration/data/criteres_repartition_2023.csv...
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:50: DtypeWarning: Columns (2,19,37,39,43,45,52,57,59,65,66,79,98,102,108,130,138,140,141,142,143,149,151,152,157,166,167,168,169,171,175,176,177) have mixed types. Specify dtype option on import or set low_memory=False.
dgcl_data = read_csv(csv_path, decimal=DECIMAL_SEPARATOR_2024, dtype={CODE_INSEE_2024: CODE_INSEE_DTYPE_2024})
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:117: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits[nom_ofdl] = data[nom_dgcl]
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:126: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits["dsu_montant_eligible"] = (
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:136: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits["dsr_montant_hors_garanties_fraction_perequation"] = data[
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:144: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits["dsr_montant_eligible_fraction_perequation"] = (
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:153: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
resultats_extraits["dsr_montant_hors_garanties_fraction_cible"] = data[
🔹 INFO
Loading /Users/sch/dev/gitruc/data-exploration/data/criteres_repartition_2024.csv...
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/leximpact_dotations_back/data_building/build_dotations_data.py:50: DtypeWarning: Columns (2,19,25,26,35,36,38,42,44,51,57,59,63,64,77,105,119,120,121,122,135,137,138,139,145,147,148,154,159) have mixed types. Specify dtype option on import or set low_memory=False.
dgcl_data = read_csv(csv_path, decimal=DECIMAL_SEPARATOR_2024, dtype={CODE_INSEE_2024: CODE_INSEE_DTYPE_2024})
🔸 WARNING
Specific treatment applied to some communes: 57163 and 87116
%% Cell type:code id: tags:
``` python
from numpy import where
codes_insee_2024 = simulation_2024.calculate("code_insee", f"{YEAR}-01")
index_commune_in_simulation = where(codes_insee_2024 == CODE_INSEE_COMMUNE)[0][0]
df_simulee_2024 = simulation_2024.calculate("dotation_forfaitaire", YEAR)[index_commune_in_simulation]
dsr_simulee_2024 = simulation_2024.calculate("dotation_solidarite_rurale", YEAR)[index_commune_in_simulation]
dsu_simulee_2024 = simulation_2024.calculate("dsu_montant", YEAR)[index_commune_in_simulation]
print(f"[🧳 DF] Simulée : {df_simulee_2024}")
print(f"[🌻 DSR] Simulée : {dsr_simulee_2024}")
print(f"[🏢 DSU] Simulée : {dsu_simulee_2024}")
```
%% Output
[🧳 DF] Simulée : 13512.0
[🌻 DSR] Simulée : 44.650325775146484
[🏢 DSU] Simulée : nan
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/openfisca_france_dotations_locales/variables/dotation_forfaitaire.py:190: RuntimeWarning: divide by zero encountered in log10
dotation_supp_par_habitant = facteur_minimum + (facteur_maximum - facteur_minimum) * max_(0, min_(1, facteur_du_coefficient_logarithmique * log10(safe_divide(population_majoree_dgf, plancher_dgcl_population_dgf_majoree, 1))))
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/openfisca_france_dotations_locales/variables/dotation_forfaitaire.py:40: RuntimeWarning: divide by zero encountered in log10
coefficient_logarithmique = max_(1, min_(2, 1 + facteur_du_coefficient_logarithmique * log10(population_dgf / plancher_dgcl_population_dgf)))
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/openfisca_france_dotations_locales/variables/dotation_forfaitaire.py:72: RuntimeWarning: divide by zero encountered in divide
potentiel_fiscal_moyen_commune = where(population_logarithmee > 0, potentiel_fiscal / population_logarithmee, 0)
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/openfisca_france_dotations_locales/variables/dotation_forfaitaire.py:157: RuntimeWarning: divide by zero encountered in divide
potentiel_fiscal_moyen_commune = where(population_logarithmee > 0, potentiel_fiscal / population_logarithmee, 0)
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/openfisca_france_dotations_locales/variables/dotation_solidarite_urbaine.py:411: RuntimeWarning: invalid value encountered in divide
pourcentage_augmentation_dsu = dsu_montant_total / dsu_an_precedent - 1
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/openfisca_france_dotations_locales/variables/dotation_solidarite_urbaine.py:425: RuntimeWarning: invalid value encountered in divide
facteur_qpv = (1 + np.where(population_insee > 0, poids_quartiers_prioritaires_ville * population_qpv / population_insee, 0))
/Users/sch/Library/Caches/pypoetry/virtualenvs/data-exploration-VsNz68cn-py3.11/lib/python3.11/site-packages/openfisca_france_dotations_locales/variables/dotation_solidarite_urbaine.py:426: RuntimeWarning: invalid value encountered in divide
facteur_zfu = (1 + np.where(population_insee > 0, poids_zone_franche_urbaine * population_zfu / population_insee, 0))
%% Cell type:markdown id: tags:
## Analyse de [in]cohérence
%% Cell type:code id: tags:
``` python
index_commune_in_criteres_bruts = data_brutes_criteres.index[data_brutes_criteres['Informations générales - Code INSEE de la commune'] == CODE_INSEE_COMMUNE][0]
index_commune_in_adapted_criteres = dotations_adapted_criteres_2024.index[dotations_adapted_criteres_2024['code_insee'] == CODE_INSEE_COMMUNE][0]
assert index_commune_in_criteres_bruts == index_commune_in_adapted_criteres
assert index_commune_in_criteres_bruts == index_commune_in_simulation
```
%% Cell type:code id: tags:
``` python
print(f"[🧳 DF] Écarts calculée par simulation [{df_simulee_2024}] - officielle notifiée [{df_notifiee_2024}] : {df_simulee_2024 - df_notifiee_2024}")
print(f"[🌻 DSR] Écarts calculée par simulation [{dsr_simulee_2024}] - officielle notifiée [{dsr_notifiee_2024}] : {dsr_simulee_2024 - dsr_notifiee_2024}")
print(f"[🏢 DSU] Écarts calculée par simulation [{dsu_simulee_2024} - officielle notifiée [{dsu_notifiee_2024}] : {dsu_simulee_2024 - dsu_notifiee_2024}")
```
%% Output
[🧳 DF] 15 288
[🌻 DSR] 10 783
[🏢 DSU] 0
[🧳 DF] Écarts calculée par simulation [13512.0] - officielle notifiée [15288] : -1776.0
[🌻 DSR] Écarts calculée par simulation [44.650325775146484] - officielle notifiée [10783] : -10738.349674224854
[🏢 DSU] Écarts calculée par simulation [nan - officielle notifiée [0] : nan
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment