Finding the genre with the largest total

Write code · Medium · §5.1 Checking the question and the data

The long-format DataFrame sales holds a bookstore's monthly sales by genre. Each row is the number of copies sold in one genre in one month.

Add up the copies sold from January to April for each genre, and print only the name of the genre with the largest total. Grading runs your code again with different sales and different recorded months.

Starter code

import pandas as pd

sales = pd.DataFrame({
    "month": [1, 2, 3, 4] * 3,
    "genre": ["Comics"] * 4 + ["Essay"] * 4 + ["Novel"] * 4,
    "sold": [30, 32, 85, 28, 41, 45, 44, 47, 38, 40, 39, 42],
})

# Write your code here

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.