# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Préparation des données

# ### Import des librairies

import pandas as pd
import numpy as np

# ### Création du dataset

data = {'Prénom': ["Yann","Hugo","Andrew"], 'Nom': [ "Lecun","Larochelle","Ng"],'age': ["53", np.NaN, "Etats-Unis"],'Ville': ["New-York", "Canada", "42"],'Profession': ["Chercheur", "Chercheur", "Chercheur"]}
df = pd.DataFrame(data=data)
df

# ## Data Cleaning :

# On supprime la colonne Profession qui n'a pas de valeur :

df.drop(columns=["Profession"], inplace=True)

df = df.set_value(1, "age", "47")
df = df.set_value(2, "age", "42")
df.at[1, "age"] = 47
df.at[2, "age"] = 42


df

df.at[2, "Ville"] = "San Francisco"

df.head() #uniquement les premières lignes

# ## Feature engineering :

# ### Date :

date = {'Date': ["11/03/2018","01/03/2018"]}
df_date = pd.DataFrame(data=date)
df_date

df_date.dtypes

df_date['Date'] = pd.to_datetime(df_date['Date'])

df_date.dtypes

# +
from datetime import datetime
 
df_date['Year'] = df_date['Date'].apply(lambda x: x.year)
df_date['Month'] = df_date['Date'].apply(lambda x: x.month)
df_date.head()
# -

seasons = [0,0,1,1,1,2,2,2,3,3,3,0] #dec - feb is winter, then spring, summer, fall etc
df_date['seasons'] = df_date['Month'].apply(lambda x: seasons[x-1])

df_date

StarcoderdataJupyterScriptsDedupFiltered