Skip to content

Commit 8fd7c66

Browse files
authored
Update
1 parent d91549a commit 8fd7c66

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

pandas/core/indexes/datetimelike.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex, ABC):
8989
_data: DatetimeArray | TimedeltaArray | PeriodArray
9090

9191
def mean(self, *, skipna: bool = True, axis: int | None = 0):
92-
"""
92+
"""
9393
Return the mean value of the Array.
9494
9595
Parameters
@@ -103,9 +103,25 @@ def mean(self, *, skipna: bool = True, axis: int | None = 0):
103103
-------
104104
scalar
105105
Timestamp or Timedelta.
106+
107+
See Also
108+
--------
109+
DatetimeIndex.median : Return the median of the index.
110+
DatetimeIndex.sum : Sum of the values in the index.
111+
DatetimeIndex.inferred_freq : Attempt to infer frequency from values.
112+
113+
Examples
114+
--------
115+
>>> import pandas as pd
116+
>>> idx = pd.date_range("2020-01-01", periods=3)
117+
>>> idx
118+
DatetimeIndex(['2020-01-01', '2020-01-02', '2020-01-03'],
119+
dtype='datetime64[ns]', freq='D')
120+
>>> idx.mean()
121+
Timestamp('2020-01-02 00:00:00')
106122
"""
107123
return self._data.mean(skipna=skipna, axis=axis)
108-
124+
109125
@property
110126
def freq(self) -> BaseOffset | None:
111127
"""
@@ -149,6 +165,24 @@ def asi8(self) -> npt.NDArray[np.int64]:
149165
def freqstr(self) -> str:
150166
"""
151167
Return the frequency string if it is set, otherwise None.
168+
169+
Returns
170+
-------
171+
str or None
172+
Frequency string such as 'D', 'H', etc., or None.
173+
174+
See Also
175+
--------
176+
DatetimeIndex.freq : The offset object for the frequency.
177+
PeriodIndex.freq : Return the frequency object for PeriodIndex.
178+
DatetimeIndex.inferred_freq : Attempt to infer frequency from values.
179+
180+
Examples
181+
--------
182+
>>> import pandas as pd
183+
>>> idx = pd.date_range("2020-01-01", periods=3, freq="D")
184+
>>> idx.freqstr
185+
'D'
152186
"""
153187
from pandas import PeriodIndex
154188

@@ -583,14 +617,28 @@ def shift(self, periods: int = 1, freq=None) -> Self:
583617
)
584618
return type(self)._simple_new(result, name=self.name)
585619

586-
@cache_readonly
620+
@cache_readonly
587621
def inferred_freq(self) -> str | None:
588622
"""
589623
Tries to return a string representing a frequency guess generated by infer_freq.
590624
591625
Returns
592626
-------
593627
str or None
628+
Inferred frequency string (e.g. 'D', 'H') or None if it cannot be inferred.
629+
630+
See Also
631+
--------
632+
DatetimeIndex.freqstr : Readable frequency string.
633+
DatetimeIndex.freq : The offset object for the frequency.
634+
pandas.infer_freq : Lower-level frequency inference utility.
635+
636+
Examples
637+
--------
638+
>>> import pandas as pd
639+
>>> idx = pd.to_datetime(['2020-01-01', '2020-01-02', '2020-01-03'])
640+
>>> idx.inferred_freq
641+
'D'
594642
"""
595643
return self._data.inferred_freq
596644

0 commit comments

Comments
 (0)