Skip to content

Commit 9bd697d

Browse files
author
IHackPY
committed
Updated DocString DatetimeIndex.tz_localize
1 parent aedbd94 commit 9bd697d

File tree

2 files changed

+160
-7
lines changed

2 files changed

+160
-7
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,15 +1937,18 @@ def tz_convert(self, tz):
19371937
mapping={True: 'infer', False: 'raise'})
19381938
def tz_localize(self, tz, ambiguous='raise', errors='raise'):
19391939
"""
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+
19421945
19431946
Parameters
19441947
----------
19451948
tz : string, pytz.timezone, dateutil.tz.tzfile or None
19461949
Time zone for time. Corresponding timestamps would be converted to
19471950
time zone of the TimeSeries.
1948-
None will remove timezone holding local time.
1951+
None will remove timezone holding local time
19491952
ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
19501953
- 'infer' will attempt to infer fall dst-transition hours based on
19511954
order
@@ -1964,18 +1967,33 @@ def tz_localize(self, tz, ambiguous='raise', errors='raise'):
19641967
19651968
.. versionadded:: 0.19.0
19661969
1967-
infer_dst : boolean, default False
1968-
.. deprecated:: 0.15.0
1969-
Attempt to infer fall dst-transition hours based on order
19701970
19711971
Returns
19721972
-------
19731973
localized : DatetimeIndex
19741974
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+
19751993
Raises
19761994
------
19771995
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
19791997
"""
19801998
if self.tz is not None:
19811999
if tz is None:

0 commit comments

Comments
 (0)