This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PSEUDO_DATABASE = { | |
'students': [{ | |
'_id': '1234', | |
'name': 'John Doe', | |
'age': 15 | |
},{ | |
'_id': '1235', | |
'name': 'Jane Dane', | |
'age': 14 | |
}], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
g = sns.FacetGrid(grouped_by_country_and_continent, col='Continent', col_wrap=3, height=4.5) | |
g = g.map(plt.hist, "Life Ladder",bins=np.arange(0,10,0.5)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sns.set( | |
font_scale=1.5, | |
rc={'figure.figsize':(20,10)} | |
) | |
ax = sns.lineplot( | |
x='Year', | |
y='Life Ladder', | |
hue='Continent', | |
marker="o", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import datetime | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
%matplotlib inline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
draw_heatmap( | |
data=data, | |
outer_row='Timing of Meal', | |
outer_col='Type of Meal', | |
inner_row='Meal Price / Order Value', | |
inner_col='Number Participants', | |
values='Converted' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Aggregate the data a bit | |
orders_with_meals['Meal Price / Order Value'] = orders_with_meals['Meal Price']/orders_with_meals['Order Value'] | |
orders_with_meals['Meal Price / Order Value'] = pd.qcut( | |
orders_with_meals['Meal Price / Order Value']*-1, | |
5, | |
labels = ['Least Expensive','Less Expensive','Proportional','More Expensive','Most Expensive'][::-1] | |
) | |
orders_with_meals['Timing of Meal'] = pd.qcut( | |
orders_with_meals['Days of meal before order'], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def draw_heatmap(data,inner_row, inner_col, outer_row, outer_col, values): | |
sns.set(font_scale=1) | |
fg = sns.FacetGrid( | |
data, | |
row=outer_row, | |
col=outer_col, | |
margin_titles=True | |
) | |
position = left, bottom, width, height = 1.4, .2, .1, .6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = orders_with_meals.groupby(['Days of meal before order']).agg( | |
{'Converted': np.mean} | |
) | |
plot_bars(data=_,x_col='Days of meal before order',y_col='Converted') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orders_with_meals['Type of Meal'].fillna('no meal',inplace=True) | |
_ = orders_with_meals.groupby('Type of Meal').agg({'Converted': np.mean}) | |
plot_bars(_,x_col='Type of Meal',y_col='Converted') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_bars(data,x_col,y_col): | |
data = data.reset_index() | |
sns.set( | |
font_scale=1.5, | |
style="whitegrid", | |
rc={'figure.figsize':(20,7)} | |
) | |
g = sns.barplot(x=x_col, y=y_col, data=data, color='royalblue') | |
for p in g.patches: |