...

/

Challenge Solution Review

Challenge Solution Review

In this lesson, we would explain the solution to the last challenge lesson.

Solution review - group by a single column

Press + to interact
import pandas as pd
df = pd.read_csv("raw_data.csv",
sep=",",
header=0)
male_total = df.groupby(["Gender"]).get_group("Male").sum()["Price"]
female_mean = df.groupby(["Gender"]).get_group("Female").mean()["Price"]
print("The total price of male group is {}.".format(male_total))
print("The mean price of female group is {}".format(female_mean))
print(male_total, female_mean)

From line 3 to line 5, the CSV file is loaded to ...