Screen Link:
https://app.dataquest.io/m/1020/dictionaries/7/average-by-group
My Code:
def avg_group(d,col):
d1={}
d1=d[col]
d2={}
avg_tb=0
avg_tip=0
avg_size=0
flipped={}
for k,v in d1.items():
if v not in flipped:
flipped[v] = [k]
else:
flipped[v].append(k)
avg_list=[]
ave_list=[]
for i in flipped:
ave_list = flipped.get(i)
for a in ave_list:
avg_tb+=d["total_bill"][a]
avg_tip+=d["tip"][a]
avg_size+= d["size"][a]
avg_list.append(avg_tb/(len(ave_list)))
avg_list.append(avg_tip/(len(ave_list)))
avg_list.append(avg_size/(len(ave_list)))
d2[i]=avg_list
return d2
What I expected to happen:
to application confirm the method works right
What actually happened:
Function avg_group
did not return the expected value.
Replace this line with the output/error
Function avg_group
did not return the expected value.
I am stuck in this practice. I wonder why the provided answers are in much higher level than what I learnt here. I even do not understand what does it do. I appreciate if you provide a description along with the answers so I can learn much more and understand the code.