o.messous
3 years ago
1 changed files with 112 additions and 0 deletions
@ -0,0 +1,112 @@ |
|||||
|
# IMPORTS |
||||
|
import pandas as pd |
||||
|
|
||||
|
# Georisque |
||||
|
|
||||
|
emission = pd.read_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/emissions.csv",error_bad_lines=False, sep=";") |
||||
|
etablissements = pd.read_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/etablissements.csv",error_bad_lines=False, sep=";") |
||||
|
Prelevements = pd.read_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Prelevements.csv",error_bad_lines=False, sep=";") |
||||
|
Prod_dechets_dangereux = pd.read_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Prod_dechets_dangereux.csv",error_bad_lines=False, sep=";") |
||||
|
Prod_dechets_non_dangereux = pd.read_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Prod_dechets_non_dangereux.csv",error_bad_lines=False, sep=";") |
||||
|
Trait_dechets_dangereux = pd.read_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Trait_dechets_dangereux.csv",error_bad_lines=False, sep=";") |
||||
|
Trait_dechets_non_dangereux = pd.read_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Trait_dechets_non_dangereux.csv",error_bad_lines=False, sep=";") |
||||
|
|
||||
|
# On retire la modalité tota pour le dioxyde de carbone car somme l'ensemble de dioxyde |
||||
|
emission2 = emission.loc[emission['polluant'] != "Dioxyde de carbone (CO2) total (d'origine biomasse et non biomasse)"] |
||||
|
|
||||
|
|
||||
|
# on garde uniquement les variables necessaires |
||||
|
emission_v = emission2.drop(emission2.columns[[1, 2, 4]], axis=1) |
||||
|
# pas besoin de faire de group by pour la table prelevements |
||||
|
Prelevements_v = Prelevements.drop(Prelevements.columns[[1,2]], axis=1) |
||||
|
Prod_dechets_dangereux_v = Prod_dechets_dangereux.drop(Prod_dechets_dangereux.iloc[:,1:10],1) |
||||
|
Prod_dechets_non_dangereux_v = Prod_dechets_non_dangereux.drop(Prod_dechets_non_dangereux.iloc[:,1:10],1) |
||||
|
Trait_dechets_dangereux_v = Prod_dechets_non_dangereux.drop(Prod_dechets_non_dangereux.iloc[:,1:10],1) |
||||
|
Trait_dechets_non_dangereux_v = Trait_dechets_non_dangereux.drop(Trait_dechets_non_dangereux.iloc[:,1:11],1) |
||||
|
|
||||
|
# Rename des variables pour differencier les differentes quantites |
||||
|
emission_v2 = emission_v.rename(columns={'milieu': 'milieu1', 'quantite': 'quantite1'}) |
||||
|
Prod_dechets_dangereux_v2 = Prod_dechets_dangereux_v.rename(columns={'quantite': 'quantite_prod_dang'}) |
||||
|
Prod_dechets_non_dangereux_v2 = Prod_dechets_non_dangereux_v.rename(columns={'quantite': 'quantite_prod_non_dang'}) |
||||
|
Trait_dechets_dangereux_v2 = Trait_dechets_dangereux_v.rename(columns={'quantite': 'quantite_trait_dang'}) |
||||
|
Trait_dechets_non_dangereux_v2 = Trait_dechets_non_dangereux_v.rename(columns={'quantite_traitee': 'quantite_trait_non_dang'}) |
||||
|
|
||||
|
|
||||
|
# group by pour n'avoir qu'une ligne par identifiant et milieu |
||||
|
emission_g = emission_v2.groupby(['identifiant', 'milieu1'], as_index=False).sum() |
||||
|
Prod_dechets_dangereux_g = Prod_dechets_dangereux_v2.groupby(['identifiant'], as_index=False).sum() |
||||
|
Prod_dechets_non_dangereux_g = Prod_dechets_non_dangereux_v2.groupby(['identifiant'], as_index=False).sum() |
||||
|
Trait_dechets_dangereux_g = Trait_dechets_dangereux_v2.groupby(['identifiant'], as_index=False).sum() |
||||
|
Trait_dechets_non_dangereux_g = Trait_dechets_non_dangereux_v2.groupby(['identifiant'], as_index=False).sum() |
||||
|
|
||||
|
# Transformation de la table emission pour passer d'une ligne par identifiant et une colonne par milieu |
||||
|
emission_g.loc[emission_g['milieu1'] == 'Air', 'qte_air'] = emission_g['quantite1'] |
||||
|
emission_g.loc[emission_g['milieu1'] == 'Sol', 'qte_sol'] = emission_g['quantite1'] |
||||
|
emission_g.loc[emission_g['milieu1'] == 'Eau (direct)', 'qte_eau_d'] = emission_g['quantite1'] |
||||
|
emission_g.loc[emission_g['milieu1'] == 'Eau (indirect)', 'qte_eau_i'] = emission_g['quantite1'] |
||||
|
|
||||
|
emission_2 = emission_g.drop(columns=["milieu1", "quantite1"]) |
||||
|
emission_g2 = emission_2.groupby(['identifiant'], as_index=False).sum() |
||||
|
|
||||
|
|
||||
|
# on met l'identifiant en str |
||||
|
|
||||
|
etablissements['identifiant'] = etablissements['identifiant'].apply(str) |
||||
|
emission_g2['identifiant'] = emission_g2['identifiant'].apply(str) |
||||
|
Prelevements_v['identifiant'] = Prelevements_v['identifiant'].apply(str) |
||||
|
Prod_dechets_dangereux_g['identifiant'] = Prod_dechets_dangereux_g['identifiant'].apply(str) |
||||
|
Prod_dechets_non_dangereux_g['identifiant'] = Prod_dechets_non_dangereux_g['identifiant'].apply(str) |
||||
|
Trait_dechets_dangereux_g['identifiant'] = Trait_dechets_dangereux_g['identifiant'].apply(str) |
||||
|
Trait_dechets_non_dangereux_g['identifiant'] = Trait_dechets_non_dangereux_g['identifiant'].apply(str) |
||||
|
|
||||
|
#Traitement du code postal sur 5 caractères |
||||
|
etablissements['code_postal'] = etablissements['code_postal'].apply(lambda x : str(x).zfill(5)) |
||||
|
|
||||
|
|
||||
|
# Merge |
||||
|
merge1 = etablissements.merge(emission_g2, how='left', on='identifiant') |
||||
|
merge2 = merge1.merge(Prelevements_v, how='left', on='identifiant') |
||||
|
merge3 = merge2.merge(Prod_dechets_dangereux_g, how='left', on='identifiant') |
||||
|
merge4 = merge3.merge(Prod_dechets_non_dangereux_g, how='left', on='identifiant') |
||||
|
merge5 = merge4.merge(Trait_dechets_dangereux_g, how='left', on='identifiant') |
||||
|
merge6 = merge5.merge(Trait_dechets_non_dangereux_g, how='left', on='identifiant') |
||||
|
|
||||
|
|
||||
|
|
||||
|
# verif |
||||
|
emission_g2.info() |
||||
|
emission.describe() |
||||
|
|
||||
|
etablissements.info() |
||||
|
etablissements.describe() |
||||
|
|
||||
|
Prelevements_v.info() |
||||
|
Prelevements_v.describe() |
||||
|
|
||||
|
Prod_dechets_dangereux_g.info() |
||||
|
Prod_dechets_dangereux_g.describe() |
||||
|
|
||||
|
Prod_dechets_non_dangereux_g.info() |
||||
|
Prod_dechets_non_dangereux_g.describe() |
||||
|
|
||||
|
Trait_dechets_dangereux_g.info() |
||||
|
Trait_dechets_dangereux_g.describe() |
||||
|
|
||||
|
Trait_dechets_non_dangereux_g.info() |
||||
|
Trait_dechets_non_dangereux_g.describe() |
||||
|
|
||||
|
# Export |
||||
|
|
||||
|
emission_g2.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/emission_final.csv") |
||||
|
etablissements.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/etablissement_final.csv") |
||||
|
Prelevements_v.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Prelevement_final.csv") |
||||
|
Prod_dechets_dangereux_g.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Prod_dangereux_final.csv") |
||||
|
Prod_dechets_non_dangereux_g.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Prod_non_dangereux_final.csv") |
||||
|
Trait_dechets_dangereux_g.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Trait_dechets_dangereux_g.csv") |
||||
|
Trait_dechets_non_dangereux_g.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/1. Installations industrielles rejetant des polluants/Trait_non_dangereux_final.csv") |
||||
|
|
||||
|
merge6.to_csv("C:/Oumayma/PSB M2/S9/SCRUM/bdd/bdd_final.csv") |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue