From 1e200acdaa89379eb4dbaad32de67ac6687d8f61 Mon Sep 17 00:00:00 2001 From: Moi Date: Wed, 19 Sep 2018 18:41:05 +0200 Subject: [PATCH 1/4] Upadated documentation for the pandas.Series.autocorr method --- pandas/core/series.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index fdb9ef59c1d3e..4bb643e4311eb 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 ---------- @@ -2030,7 +2033,33 @@ 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. + + Notes + ----- + return Nan if the computation of the autocorr is not possible. + + 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 between self and self.shift(lag) cannot be + computed, then nan is returned. + + >>> s = pd.Series([1, 0, 0, 0]) + >>> s.autocorr() + nan """ return self.corr(self.shift(lag)) From f0aae5d0b4afab07674eeb2b528aba0360f37bb8 Mon Sep 17 00:00:00 2001 From: Moi Date: Fri, 21 Sep 2018 13:31:22 +0200 Subject: [PATCH 2/4] updated changes to Series_autocorr documentation --- pandas/core/series.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 4bb643e4311eb..8289a686d78ea 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2034,15 +2034,19 @@ def autocorr(self, lag=1): Returns ------- float - The Pearson correlation between self and self.shift(lag). + The pearson correlation between self and self.shift(lag). - See also + 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. Notes ----- - return Nan if the computation of the autocorr is not possible. + If the pearson correlation is not well defined return 'NaN'. Examples -------- @@ -2054,8 +2058,7 @@ def autocorr(self, lag=1): **Warning** - If the pearson correlation between self and self.shift(lag) cannot be - computed, then nan is returned. + If the pearson correlation is not well defined, then 'NaN' is returned. >>> s = pd.Series([1, 0, 0, 0]) >>> s.autocorr() From 99e76372a97096ebc3c9a62fba9a9eee1f4d495d Mon Sep 17 00:00:00 2001 From: Moi Date: Sun, 23 Sep 2018 19:01:21 +0200 Subject: [PATCH 3/4] Warning deleted --- pandas/core/series.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 8289a686d78ea..756400ce725d9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2056,8 +2056,6 @@ def autocorr(self, lag=1): >>> 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]) From 33dcb3362d0da16a1d3b5ca2de1f3358897109d5 Mon Sep 17 00:00:00 2001 From: Moi Date: Sun, 23 Sep 2018 19:42:00 +0200 Subject: [PATCH 4/4] Changed pearson into Pearson --- pandas/core/series.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 756400ce725d9..eef64fe68c360 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2023,7 +2023,7 @@ def autocorr(self, lag=1): """ Compute the lag-N autocorrelation. - This method computes the pearson correlation between + This method computes the Pearson correlation between the Series and its shifted self. Parameters @@ -2034,7 +2034,7 @@ def autocorr(self, lag=1): Returns ------- float - The pearson correlation between self and self.shift(lag). + The Pearson correlation between self and self.shift(lag). See Also -------- @@ -2046,7 +2046,7 @@ def autocorr(self, lag=1): Notes ----- - If the pearson correlation is not well defined return 'NaN'. + If the Pearson correlation is not well defined return 'NaN'. Examples -------- @@ -2056,7 +2056,7 @@ def autocorr(self, lag=1): >>> s.autocorr(lag=2) -0.9999999999999999 - If the pearson correlation is not well defined, then 'NaN' is returned. + If the Pearson correlation is not well defined, then 'NaN' is returned. >>> s = pd.Series([1, 0, 0, 0]) >>> s.autocorr()