pandas.DatetimeIndex.mean#

DatetimeIndex.mean(*, axis=None, dtype=None, out=None, keepdims=False, skipna=True)[source]#

Return the mean value of the Array.

This method computes the arithmetic mean of the datetime or timedelta values in the index, optionally skipping NaT values.

Parameters:
axis{None, 0}

Unused. Parameter needed for compatibility with numpy.

dtype, outNone

Not implemented; kept for compatibility with numpy.mean(), which calls this method. Must be left at the default.

keepdimsbool, default False

Not implemented; must be left at the default.

skipnabool, default True

Whether to ignore any NaT elements.

Returns:
scalar

Timestamp or Timedelta.

See also

numpy.ndarray.mean

Returns the average of array elements along a given axis.

Series.mean

Return the mean value in a Series.

Notes

mean is only defined for Datetime and Timedelta dtypes, not for Period.

Examples

For pandas.DatetimeIndex:

>>> idx = pd.date_range("2001-01-01 00:00", periods=3)
>>> idx
DatetimeIndex(['2001-01-01', '2001-01-02', '2001-01-03'],
              dtype='datetime64[us]', freq='D')
>>> idx.mean()
Timestamp('2001-01-02 00:00:00')

For pandas.TimedeltaIndex:

>>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit="D")
>>> tdelta_idx
TimedeltaIndex(['1 days', '2 days', '3 days'],
                dtype='timedelta64[us]', freq=None)
>>> tdelta_idx.mean()
Timedelta('2 days 00:00:00')