|
@ -0,0 +1,67 @@ |
|
|
|
|
|
#!/usr/bin/env python |
|
|
|
|
|
# coding: utf-8 |
|
|
|
|
|
|
|
|
|
|
|
# In[35]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Importer les librairies |
|
|
|
|
|
import pandas as pd |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[36]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Ouvrir un fichier CSV |
|
|
|
|
|
df = pd.read_csv (r'/Users/marinegalanth/Desktop/inondation_bdd/bd_inondation/_n_commune_s.csv') |
|
|
|
|
|
print(df) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[37]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Renommer les colonnes sélectionnées |
|
|
|
|
|
df = df.rename(columns={'code_insee,C,80': 'codepostal', 'nom_com,C,80': 'nomcommune', 'id_si_ext,C,80': 'id', 'id_tri,C,80': 'id_tri'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[39]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Dupliquer la colonne : code_postal > créer une nouvelle colonne nommée dep_code |
|
|
|
|
|
#avec les valeurs de code_postal |
|
|
|
|
|
df=df.assign(codedept=df['codepostal']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[40]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Supprimer les 8 premiers caractères des valeurs de la colonne id_tri |
|
|
|
|
|
#Supprimer les caractères inutiles suivant : FRM_TRI_ |
|
|
|
|
|
df["id_tri"]=df["id_tri"].str[8:] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[41]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Garder uniquement les 2 premiers caractères des valeurs de la colonne dept |
|
|
|
|
|
df["codedept"]=df["codedept"].str[:2] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[44]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Conserver uniquement les colonnes utiles |
|
|
|
|
|
df2=df[["codepostal","nomcommune","id","id_tri","codedept"]] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[45]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Afficher le dataframe |
|
|
|
|
|
df2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# In[ ]: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|