Localize time zone naive index of a Series or DataFrame to target time zone. This operation localizes the Index. To localize the values in a time zone naive Series, use :meth:`Series.dt.tz_localize`. Parameters ---------- tz : str or tzinfo or None
(
self,
tz,
axis: Axis = 0,
level=None,
copy: bool | lib.NoDefault = lib.no_default,
ambiguous: TimeAmbiguous = "raise",
nonexistent: TimeNonexistent = "raise",
)
| 10953 | |
| 10954 | @final |
| 10955 | def tz_localize( |
| 10956 | self, |
| 10957 | tz, |
| 10958 | axis: Axis = 0, |
| 10959 | level=None, |
| 10960 | copy: bool | lib.NoDefault = lib.no_default, |
| 10961 | ambiguous: TimeAmbiguous = "raise", |
| 10962 | nonexistent: TimeNonexistent = "raise", |
| 10963 | ) -> Self: |
| 10964 | """ |
| 10965 | Localize time zone naive index of a Series or DataFrame to target time zone. |
| 10966 | |
| 10967 | This operation localizes the Index. To localize the values in a |
| 10968 | time zone naive Series, use :meth:`Series.dt.tz_localize`. |
| 10969 | |
| 10970 | Parameters |
| 10971 | ---------- |
| 10972 | tz : str or tzinfo or None |
| 10973 | Time zone to localize. Passing ``None`` will remove the |
| 10974 | time zone information and preserve local time. |
| 10975 | axis : {0 or 'index', 1 or 'columns'}, default 0 |
| 10976 | The axis to localize |
| 10977 | level : int, str, default None |
| 10978 | If axis ia a MultiIndex, localize a specific level. Otherwise |
| 10979 | must be None. |
| 10980 | copy : bool, default False |
| 10981 | This keyword is now ignored; changing its value will have no |
| 10982 | impact on the method. |
| 10983 | |
| 10984 | .. deprecated:: 3.0.0 |
| 10985 | |
| 10986 | This keyword is ignored and will be removed in pandas 4.0. Since |
| 10987 | pandas 3.0, this method always returns a new object using a lazy |
| 10988 | copy mechanism that defers copies until necessary |
| 10989 | (Copy-on-Write). See the `user guide on Copy-on-Write |
| 10990 | <https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__ |
| 10991 | for more details. |
| 10992 | |
| 10993 | ambiguous : 'infer', bool, bool-ndarray, 'NaT', default 'raise' |
| 10994 | When clocks moved backward due to DST, ambiguous times may arise. |
| 10995 | For example in Central European Time (UTC+01), when going from |
| 10996 | 03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at |
| 10997 | 00:30:00 UTC and at 01:30:00 UTC. In such a situation, the |
| 10998 | `ambiguous` parameter dictates how ambiguous times should be |
| 10999 | handled. |
| 11000 | |
| 11001 | - 'infer' will attempt to infer fall dst-transition hours based on |
| 11002 | order |
| 11003 | - bool (or bool-ndarray) where True signifies a DST time, False designates |
| 11004 | a non-DST time (note that this flag is only applicable for |
| 11005 | ambiguous times) |
| 11006 | - 'NaT' will return NaT where there are ambiguous times |
| 11007 | - 'raise' will raise a ValueError if there are ambiguous |
| 11008 | times. |
| 11009 | nonexistent : str, default 'raise' |
| 11010 | A nonexistent time does not exist in a particular timezone |
| 11011 | where clocks moved forward due to DST. Valid values are: |
| 11012 |