...

/

Challenge Solution Review

Challenge Solution Review

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

Solution review - Find the most popular item

Press + to interact
import pandas as pd
df = pd.read_csv("raw_data.csv",
sep=",",
header=0)
df = df.groupby(["Item ID"]).count()
df.rename(columns={"Price": "Item Count"}, inplace=True)
ic = df.sort_values("Item Count", ascending=False).head(1)["Item Count"]
print(ic.index[0])
print(ic.values[0])

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

line 7 groups the data by the Item ID column, meanwhile, count() is performed on ...