How does timezone handling work with tz_localize and tz_convert in pandas?

Quick Overview

Asks how pandas handles timezones with tz_localize and tz_convert and when each method applies. It tests whether you can tell wall-clock time from the underlying instant, handle daylight saving transitions, and order the calls correctly on an index or a datetime column.

How does timezone handling work with tz_localize and tz_convert in pandas?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

In pandas, how does timezone handling work with `tz_localize` and `tz_convert`? Explain what each method does to a timestamp and when you would use each one. ```hint Two things a timestamp carries Separate the wall-clock reading of a timestamp from the instant in time it refers to. For each method, ask which of the two it keeps fixed. ``` ```hint Transition days Think about a local time that happens twice, or never happens, on a daylight saving transition day. ``` ### What a Strong Answer Covers - What each method does to the wall-clock reading and to the underlying instant - Which input each method accepts (naive or timezone-aware) and what happens otherwise - Ambiguous and nonexistent local times around daylight saving changes, and the arguments that control them - The correct order of calls, with a short example - How to remove timezone information, and the difference between working on a column and on the index ### Follow-up Questions - Your raw log timestamps are naive but were written in UTC, and you need them in Pacific time. Which calls do you make, and what goes wrong if you localize straight to Pacific? - What is the difference between `tz_localize(None)` and `tz_convert(None)`? - How would you localize a column of local times that crosses the November fall-back hour without losing rows? - Why is converting aware timestamps between zones cheap in pandas?

Overview: Asks how pandas handles timezones with tz_localize and tz_convert and when each method applies. It tests whether you can tell wall-clock time from the underlying instant, handle daylight saving transitions, and order the calls correctly on an index or a datetime column.

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

In pandas, how does timezone handling work with tz_localize and tz_convert? Explain what each method does to a timestamp and when you would use each one.

What a Strong Answer Covers Guidance

  • What each method does to the wall-clock reading and to the underlying instant
  • Which input each method accepts (naive or timezone-aware) and what happens otherwise
  • Ambiguous and nonexistent local times around daylight saving changes, and the arguments that control them
  • The correct order of calls, with a short example
  • How to remove timezone information, and the difference between working on a column and on the index

Follow-up Questions Guidance

  • Your raw log timestamps are naive but were written in UTC, and you need them in Pacific time. Which calls do you make, and what goes wrong if you localize straight to Pacific?
  • What is the difference between tz_localize(None) and tz_convert(None) ?
  • How would you localize a column of local times that crosses the November fall-back hour without losing rows?
  • Why is converting aware timestamps between zones cheap in pandas?