You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
811 B
52 lines
811 B
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# In[2]:
|
|
#importer la librairie Pandas
|
|
import pandas as pd
|
|
|
|
|
|
# In[3]:
|
|
#ouvrir un fichier CSV
|
|
df = pd.read_csv (r'/Users/marinegalanth/Desktop/inondation_bdd/_n_commune_s.csv')
|
|
print(df)
|
|
|
|
|
|
# In[5]:
|
|
#créer un dataframe
|
|
df=pd.DataFrame(df)
|
|
|
|
|
|
# In[6]:
|
|
#afficher le dataframe
|
|
df
|
|
|
|
|
|
# In[7]:
|
|
df2=df[["code_insee,C,80","nom_com,C,80"]]
|
|
|
|
|
|
# In[8]:
|
|
#afficher la nouvelle ataframe df2
|
|
df2
|
|
|
|
|
|
# In[9]:
|
|
#dupliquer la colonne : code_insee,C,80 > créer une nouvelle colonne nommée dep_code
|
|
#avec les valeurs de code_insee,C,80
|
|
df2=df.assign(dep_code=df['code_insee,C,80'])
|
|
|
|
|
|
# In[10]:
|
|
#afficher le nouveau DataFrame
|
|
df2
|
|
|
|
|
|
# In[11]:
|
|
#selectionner uniquement les colonnes choisies dans une nouveau df3
|
|
df3=df2[["code_insee,C,80","nom_com,C,80","dep_code"]]
|
|
|
|
|
|
# In[12]:
|
|
#afficher df3
|
|
df3
|