Skip to content

Instantly share code, notes, and snippets.

@AntoineToubhans
Last active August 18, 2017 17:00
Show Gist options
  • Select an option

  • Save AntoineToubhans/4b0865a593b0565dcbb466274c3e07c4 to your computer and use it in GitHub Desktop.

Select an option

Save AntoineToubhans/4b0865a593b0565dcbb466274c3e07c4 to your computer and use it in GitHub Desktop.
import pandas as pd
def load():
df = pd.read_csv('/home/toubi/Titanic.csv', delimiter=';')
return df
def compute_max_ticket_price_per_class(df):
return { cl: df[cl == df.Class]['Ticket price'].max() for cl in range(1, 4) }
def normalize_ticket_price_per_class(df):
max_per_class = compute_max_ticket_price_per_class(df)
df['normalized_ticket_price'] = df['Ticket price'] / df.Class.apply(lambda cl: max_per_class[cl])
def run():
df = load()
normalize_ticket_price_per_class(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment