You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Bins for Age Demographicsbins= [0]
bin_value= ["<10"]
max_age=pymoli_data["Age"].max()
forxinrange(2,int(max_age/5)+2):
bins=bins+ [(x*5)-1]
forxinrange(1,len(bins)-2):
bin_value=bin_value+ [str(bins[x]+1)+"-"+str(bins[x+1])]
bin_value=bin_value+ [str(max_age) +"+"]
#print(bins)#print(bin_value)#Age Demographics - need to group by SN.. add back in age, gender.. groupby age group (count and percentage)pymoli_data["Age Group"] =pd.cut(pymoli_data["Age"],bins,labels=bin_value)
top_items=pymoli_data.groupby("Item ID")
top_items_group2=pymoli_data.groupby(["Item ID","Item Name","Price"])
top_items_count=top_items.size()
top_items_value=top_items_group2["Price"].sum()
top_items_frame=pd.DataFrame({"Purchase Count": top_items_count})
#Identify most popular itemstop_items_sort=top_items_frame.sort_values(by="Purchase Count",
ascending=False).reset_index()
end=top_items_sort["Purchase Count"].sizelastrow=0forrowinrange(4, end):
if(top_items_sort.get_value(row,"Purchase Count") !=top_items_sort.get_value(row+1,"Purchase Count")):
lastrow=rowbreakiflastrow!=4:
print("Note: As a result of ties, more than 5 items are the most popular. The tied values are printed")
top_items_filter=top_items_sort.iloc[0:lastrow+1].reset_index()
top_items_func_frame=pd.DataFrame({"Total Purchase Value": top_items_value}).reset_index()
#merge tablestop_items_final=pd.merge(top_items_filter, top_items_func_frame, on="Item ID")
#fix column order and price nametop_items_final=top_items_final[["Item ID","Item Name","Purchase Count","Price","Total Purchase Value"]]
top_items_final=top_items_final.rename(columns={"Price":"Item Price"})
top_items_final
Note: As a result of ties, more than 5 items are the most popular. The tied values are printed