AnalystPath

Odd and Even Page Counts per Shelving Day

PandasMediumMid level~10 min

Problem

You are given a DataFrame `returns_log` loaded from `returns_log.csv` with columns `return_id` (int), `page_count` (int) and `shelved_on` (date string). For each `shelved_on` day, return `odd_pages` = the sum of `page_count` over rows whose `page_count` is odd, and `even_pages` = the sum of `page_count` over rows whose `page_count` is even (treat 0 as even). Return columns `shelved_on`, `odd_pages`, `even_pages`, sorted by `shelved_on`.

Input data

Example rows — the live problem includes the full dataset.

returns_log
return_idpage_countshelved_on
11502024-09-01
22012024-09-01
3882024-09-01
43002024-09-02
5642024-09-02

Expected output

Your answer should return 3 rows with the columns shelved_on, odd_pages, even_pages.

Starter code (Pandas (Python))

import pandas as pd

def page_parity(returns_log) -> pd.DataFrame:
    # Your code here
    return returns_log

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions