Pandas DataFrame: tz_localize() function
DataFrame - tz_localize() function
The tz_localize() function is used to localize tz-naive index of a Series or DataFrame to target time zone.
This operation localizes the Index. To localize the values in a timezone-naive Series, use Series.dt.tz_localize().
Syntax:
DataFrame.tz_localize(self, tz, axis=0, level=None, copy=True, ambiguous='raise', nonexistent='raise')
Parameters:
Name | Description | Type / Default Value | Required / Optional |
---|---|---|---|
tz | string or pytz.timezone object | Required | |
axis | the axis to localize | Required | |
level | If axis ia a MultiIndex, localize a specific level. Otherwise must be None | int, str Default Value: None |
Required |
copy | Also make a copy of the underlying data | boolean Default Value: True |
Required |
ambiguous | When clocks moved backward due to DST, ambiguous times may arise. For example in Central European Time (UTC+01), when going from 03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at 00:30:00 UTC and at 01:30:00 UTC. In such a situation, the ambiguous parameter dictates how ambiguous times should be handled.
|
‘infer’, bool-ndarray, ‘NaT’, Default Value: ‘raise’ |
Required |
nonexistent | A nonexistent time does not exist in a particular timezone where clocks moved forward due to DST. Valid values are:
|
str Default Value: ‘raise’ |
Required |
Returns: Series or DataFrame
Same type as the input.
Raises: TypeError
If the TimeSeries is tz-aware and tz is not None.
Example:
Download the Pandas DataFrame Notebooks from here.
Previous: DataFrame - resample() function
Next: DataFrame.plot.area() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/dataframe/dataframe-tz_localize.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics