@@ -1937,15 +1937,18 @@ def tz_convert(self, tz):
1937
1937
mapping = {True : 'infer' , False : 'raise' })
1938
1938
def tz_localize (self , tz , ambiguous = 'raise' , errors = 'raise' ):
1939
1939
"""
1940
- Localize tz-naive DatetimeIndex to given time zone (using
1941
- pytz/dateutil), or remove timezone from tz-aware DatetimeIndex
1940
+ DatetimeIndex.tz_localize used for Localize tz-naive DatetimeIndex.
1941
+
1942
+ tz_localize method is use to convert naive DatetimeIndex into any other localize
1943
+ DatetimeIndex
1944
+
1942
1945
1943
1946
Parameters
1944
1947
----------
1945
1948
tz : string, pytz.timezone, dateutil.tz.tzfile or None
1946
1949
Time zone for time. Corresponding timestamps would be converted to
1947
1950
time zone of the TimeSeries.
1948
- None will remove timezone holding local time.
1951
+ None will remove timezone holding local time
1949
1952
ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
1950
1953
- 'infer' will attempt to infer fall dst-transition hours based on
1951
1954
order
@@ -1964,18 +1967,33 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'):
1964
1967
1965
1968
.. versionadded:: 0.19.0
1966
1969
1967
- infer_dst : boolean, default False
1968
- .. deprecated:: 0.15.0
1969
- Attempt to infer fall dst-transition hours based on order
1970
1970
1971
1971
Returns
1972
1972
-------
1973
1973
localized : DatetimeIndex
1974
1974
1975
+ Examples
1976
+ --------
1977
+ In the example below, We put the date range from 01 March 2018 to 08 March 2018
1978
+ & convert this to US/Eastern Time zone
1979
+
1980
+ >>> import pandas as pd
1981
+ >>> df = pd.date_range('2018-03-01', '2018-03-08')
1982
+ >>> df
1983
+ DatetimeIndex(['2018-03-01', '2018-03-02', '2018-03-03', '2018-03-04',
1984
+ '2018-03-05', '2018-03-06', '2018-03-07', '2018-03-08'],
1985
+ dtype='datetime64[ns]', freq='D')
1986
+ >>> df.tz_localize(tz='US/Eastern')
1987
+ DatetimeIndex(['2018-03-01 00:00:00-05:00', '2018-03-02 00:00:00-05:00',
1988
+ '2018-03-03 00:00:00-05:00', '2018-03-04 00:00:00-05:00',
1989
+ '2018-03-05 00:00:00-05:00', '2018-03-06 00:00:00-05:00',
1990
+ '2018-03-07 00:00:00-05:00', '2018-03-08 00:00:00-05:00'],
1991
+ dtype='datetime64[ns, US/Eastern]', freq='D')
1992
+
1975
1993
Raises
1976
1994
------
1977
1995
TypeError
1978
- If the DatetimeIndex is tz-aware and tz is not None.
1996
+ If the DatetimeIndex is tz-aware and tz is not None
1979
1997
"""
1980
1998
if self .tz is not None :
1981
1999
if tz is None :
0 commit comments