Odd and Even Page Counts per Shelving Day
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.
| return_id | page_count | shelved_on |
|---|---|---|
| 1 | 150 | 2024-09-01 |
| 2 | 201 | 2024-09-01 |
| 3 | 88 | 2024-09-01 |
| 4 | 300 | 2024-09-02 |
| 5 | 64 | 2024-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_logSolve 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