A DatetimeIndex holds naive timestamps that are known to be UTC. Which call turns it into a timezone-aware index?
Correct answer
D. tz_localize on the index, because tz_convert needs an aware index first
14 views
D. tz_localize on the index, because tz_convert needs an aware index first
14 views
tz_localize attaches a timezone to naive timestamps, asserting that the wall-clock values belong to that zone, while tz_convert translates an already-aware index to another zone. Calling tz_convert on a naive index raises TypeError, and tz_localize on an aware index raises unless the existing zone is passed. Getting the two backwards shifts every timestamp by the UTC offset.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.