Skip to content

Instantly share code, notes, and snippets.

@FBosler
Created August 31, 2019 14:34
Show Gist options
  • Save FBosler/0ded25f325bc384c173e91e699c164fb to your computer and use it in GitHub Desktop.
Save FBosler/0ded25f325bc384c173e91e699c164fb to your computer and use it in GitHub Desktop.
# 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'],
3,
labels = ['After Order','Around Order','Before Order']
)
data = orders_with_meals[orders_with_meals['Type of Meal'] != 'no meal'].groupby(
['Timing of Meal','Number Participants','Type of Meal','Meal Price / Order Value']
).agg({'Converted': np.mean}).unstack().fillna(0).stack().reset_index()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment