Skip to content

DOC: Updating Series.autocorr docstring #22787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,10 @@ def diff(self, periods=1):

def autocorr(self, lag=1):
"""
Lag-N autocorrelation
Compute the lag-N autocorrelation.

This method computes the pearson correlation between
the Series and its shifted self.

Parameters
----------
Expand All @@ -2030,7 +2033,36 @@ def autocorr(self, lag=1):

Returns
-------
autocorr : float
float
The pearson correlation between self and self.shift(lag).

See Also
--------
Series.corr : Compute the correlation between two Series.
Series.shift : Shift index by desired number of periods.
DataFrame.corr : Compute pairwise correlation of columns.
DataFrame.corrwith : Compute pairwise correlation between rows or
columns of two DataFrame objects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Series.shift, DataFrame.corr and DataFrame.corrwith

Notes
-----
If the pearson correlation is not well defined return 'NaN'.

Examples
--------
>>> s = pd.Series([0.25, 0.5, 0.2, -0.05])
>>> s.autocorr()
0.1035526330902407
>>> s.autocorr(lag=2)
-0.9999999999999999

**Warning**

If the pearson correlation is not well defined, then 'NaN' is returned.

>>> s = pd.Series([1, 0, 0, 0])
>>> s.autocorr()
nan
"""
return self.corr(self.shift(lag))

Expand Down