Skip to content

Commit f64f994

Browse files
HubertKlTomAugspurger
authored andcommitted
DOC: Updating Series.autocorr docstring (#22787)
1 parent 739e6be commit f64f994

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

pandas/core/series.py

+32-2
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,10 @@ def diff(self, periods=1):
20352035

20362036
def autocorr(self, lag=1):
20372037
"""
2038-
Lag-N autocorrelation
2038+
Compute the lag-N autocorrelation.
2039+
2040+
This method computes the Pearson correlation between
2041+
the Series and its shifted self.
20392042
20402043
Parameters
20412044
----------
@@ -2044,7 +2047,34 @@ def autocorr(self, lag=1):
20442047
20452048
Returns
20462049
-------
2047-
autocorr : float
2050+
float
2051+
The Pearson correlation between self and self.shift(lag).
2052+
2053+
See Also
2054+
--------
2055+
Series.corr : Compute the correlation between two Series.
2056+
Series.shift : Shift index by desired number of periods.
2057+
DataFrame.corr : Compute pairwise correlation of columns.
2058+
DataFrame.corrwith : Compute pairwise correlation between rows or
2059+
columns of two DataFrame objects.
2060+
2061+
Notes
2062+
-----
2063+
If the Pearson correlation is not well defined return 'NaN'.
2064+
2065+
Examples
2066+
--------
2067+
>>> s = pd.Series([0.25, 0.5, 0.2, -0.05])
2068+
>>> s.autocorr()
2069+
0.1035526330902407
2070+
>>> s.autocorr(lag=2)
2071+
-0.9999999999999999
2072+
2073+
If the Pearson correlation is not well defined, then 'NaN' is returned.
2074+
2075+
>>> s = pd.Series([1, 0, 0, 0])
2076+
>>> s.autocorr()
2077+
nan
20482078
"""
20492079
return self.corr(self.shift(lag))
20502080

0 commit comments

Comments
 (0)