pandas.DatetimeIndex.tz_localize

pandas 3.1.1 · Index objects · method

Assign a timezone to naive datetimes or remove it while keeping local clock values.

Call syntax

DatetimeIndex.tz_localize(tz, ambiguous='raise', nonexistent='raise')

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
tz Required
Positional or keyword
str, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile, datetime.tzinfo or None

Supply a timezone name or timezone object.

ambiguous Optional
Positional or keyword
Default 'raise'
'infer', 'NaT', bool array

Resolve local times that occur twice when clocks move backward.

nonexistent Optional
Positional or keyword
Default 'raise'
'shift_forward', 'shift_backward', 'NaT', timedelta

Resolve local times skipped when clocks move forward.

Returns

Same type as self