Want to get involved? We're always looking for ideas and content for Weekly Challenges.
SUBMIT YOUR IDEAWhat about Breyers?!
My attempt at doing it in the Python Tool,
import pandas as pd
from ayx import Alteryx
df = Alteryx.read('#1')
#################################
rows = (~df.ingredients.isna()) & (df.brand != 'breyers')
cols = ['brand', 'name', 'rating', 'ingredients']
df = df.loc[rows, cols]
#################################
rename_brand = {'bj': "Ben and Jerry's", 'hd': "Häagen-Dazs", 'talenti': 'Talenti Gelato'}
df['brand'] = df.brand.map(rename_brand)
#################################
df.rating = df.rating.astype(float)
#################################
df.groupby('brand').mean().sort_values('rating', ascending=False)
#################################
def filter_allergens(df):
'''Get all the ice cream without allergens cream and peanuts'''
mask = ~df.ingredients.str.contains('cream|peanuts', case=False)
return (
df.loc[mask]
.drop(columns='rating')
.rename(columns=lambda col:col.title())
.reset_index(drop=True)
)
filter_allergens(df)
#################################
def get_best_and_worst(df):
return (
df.sort_values('rating')
.groupby('brand')
.agg(('first', 'last'))
.rename(columns={'first':'Worst', 'last':'Best', 'name':'Ice Cream'})
.rename(columns=lambda col:col.title())
.swaplevel(0, 1, axis=1)
.sort_index(axis=1)
)
get_best_and_worst(df)
Here is my solution:
All,