Search⌘ K

Challenge Solution Review

Explore how to handle duplicate rows by dropping them based on a specific column in Pandas. Learn to group data by a categorical variable and calculate aggregated results such as the total price for a selected group, enhancing data processing and analysis skills.

Solution review - Drop duplicated rows on SN column and return the total price of male group

Python 3.5
import pandas as pd
df = pd.read_csv("raw_data.csv",
sep=",",
header=0)
df.drop_duplicates(subset=["SN"], keep="last", inplace=True)
male_total = df.groupby(["Gender"]).get_group("Male").sum()["Price"]
print(male_total)

From line 3 to ...