BuildlyBuildly
DashboardExercisesProfileHelp
Back to all

Practice: Dates & Times

Drills tagged with this skill, unpassed first. Pass them all to mark the skill ready for scenarios.

Module 3: Importing & Handling Files

0/3 done
Exercises (0/3)
  • 1
    Parse a Date Column
    Context. A date column was read from CSV as plain text. Date math and .dt operations only work once it's a real datetime type. Your task. Write to_datetime_column(df) that returns the date column converted to a pandas datetime Series. Example. the text "2021-03-15" becomes a real datetime value. Notes. Return the converted Series. Every value is a valid YYYY-MM-DD date string.
    7 min· 10 XP
  • 2
    Extract the Month from Dates
    Context. You have a column of dates and want to group sales by month — first you need the month number out of each date. Your task. Write extract_months(df) that parses the date column and returns a Series of month numbers (1-12). Example. "2021-03-15" → 3, "2021-12-01" → 12. Notes. Return a Series of integers. Parse the text to datetime first, then reach for the month.
    7 min· 10 XP
  • 3
    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.
    7 min· 10 XP