How do you handle time series data in Pandas, including creating a DatetimeIndex and parsing/formatting datetimes?

Quick Overview

Asks how to work with time series in Pandas: parsing dates, building a DatetimeIndex, and formatting datetimes back to strings. Tests practical knowledge of selection by date, resampling, rolling windows, timezone handling, and the parsing mistakes that silently corrupt time data.

How do you handle time series data in Pandas, including creating a DatetimeIndex and parsing/formatting datetimes?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How do you handle time series data in Pandas, including creating a `DatetimeIndex` and parsing and formatting datetimes? ```hint Start from the dtype After reading a CSV, check what dtype the date column has. Most of the time-series tools only work once the values are real datetimes and sit in the index. ``` ```hint Column tools and index tools Some operations go through an accessor on a column, others work directly on the index. Also think about what changes once a timestamp carries a timezone. ``` ### What a Strong Answer Covers - Parsing strings or epoch numbers into datetimes with `pd.to_datetime`, including explicit formats and handling bad values - Building a `DatetimeIndex` from a column or generating one with `pd.date_range`, and why the index should be sorted - What a time-aware index makes possible: partial-string selection, resampling and time-based rolling windows - Extracting date components and formatting datetimes back to strings - Attaching and converting timezones, including what happens around daylight saving transitions ### Follow-up Questions - A column holds values like "01/02/2023" and you do not know whether they are day-first. How do you parse it safely? - What is the difference between `resample` and `rolling`, and between `resample` and `asfreq`? - A daily series has missing days. How do you make the gaps explicit, and how do you decide whether to fill them? - What happens when you localize a timestamp that falls inside a daylight saving transition?

Overview: Asks how to work with time series in Pandas: parsing dates, building a DatetimeIndex, and formatting datetimes back to strings. Tests practical knowledge of selection by date, resampling, rolling windows, timezone handling, and the parsing mistakes that silently corrupt time data.

General logo
General
Nov 24, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How do you handle time series data in Pandas, including creating a DatetimeIndex and parsing and formatting datetimes?

What a Strong Answer Covers Guidance

  • Parsing strings or epoch numbers into datetimes with pd.to_datetime , including explicit formats and handling bad values
  • Building a DatetimeIndex from a column or generating one with pd.date_range , and why the index should be sorted
  • What a time-aware index makes possible: partial-string selection, resampling and time-based rolling windows
  • Extracting date components and formatting datetimes back to strings
  • Attaching and converting timezones, including what happens around daylight saving transitions

Follow-up Questions Guidance

  • A column holds values like "01/02/2023" and you do not know whether they are day-first. How do you parse it safely?
  • What is the difference between resample and rolling , and between resample and asfreq ?
  • A daily series has missing days. How do you make the gaps explicit, and how do you decide whether to fill them?
  • What happens when you localize a timestamp that falls inside a daylight saving transition?