BuildlyBuildly
DashboardExercisesProfileHelp
Data Science/Module 3: Importing & Handling Files/Dates & Times2/3
Exercise·7 min·10 XP

Filter Rows by Year

Context. An events table covers several years; you want only the events from one specific year.

Your task. Write rows_in_year(df, year) that returns the rows of df whose date falls in the given year. Keep the date column exactly as it came in.

Example. year=2021 keeps only rows dated in 2021, in their original order.

Notes. Parse the dates to compare years, but don't change the returned date values. No matching rows → empty DataFrame.

Previous
Extract the Month from Dates
Next
Summarize with a Pivot Table