Skip to content

Instantly share code, notes, and snippets.

PSEUDO_DATABASE = {
'students': [{
'_id': '1234',
'name': 'John Doe',
'age': 15
},{
'_id': '1235',
'name': 'Jane Dane',
'age': 14
}],
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))
sns.set(
font_scale=1.5,
rc={'figure.figsize':(20,10)}
)
ax = sns.lineplot(
x='Year',
y='Life Ladder',
hue='Continent',
marker="o",
import pandas as pd
import numpy as np
import datetime
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
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'
)
# 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'],
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
_ = 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')
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')
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: