From 4a961ab7ccdbe7569b3fa8392f01b1ce736ffab2 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Sun, 2 Jul 2023 14:50:12 +0000 Subject: [PATCH 1/7] Added note for corr --- pandas/core/frame.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index ae43a44d68f1c..6de5d2c36f262 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10430,6 +10430,12 @@ def corr( DataFrame Correlation matrix. + .. note:: + + Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method. + ``corr`` automatically considers values with matching indices. + + See Also -------- DataFrame.corrwith : Compute pairwise correlation with another @@ -10438,6 +10444,7 @@ def corr( Notes ----- + Pearson, Kendall and Spearman correlation are currently computed using pairwise complete observations. * `Pearson correlation coefficient `_ From bbae7661dfe38f0bcd6e5f6e5d13c4915a1e2e84 Mon Sep 17 00:00:00 2001 From: Rajat Subhra Mukherjee Date: Mon, 3 Jul 2023 01:46:13 +0530 Subject: [PATCH 2/7] Removed additional linebreak --- pandas/core/frame.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6de5d2c36f262..a36298f142cf1 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10435,7 +10435,6 @@ def corr( Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method. ``corr`` automatically considers values with matching indices. - See Also -------- DataFrame.corrwith : Compute pairwise correlation with another From f10ab3c336739e5db3f624ae25f8f564456cd5ff Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Wed, 5 Jul 2023 11:18:37 +0000 Subject: [PATCH 3/7] Added example and note for Series.corr --- pandas/core/frame.py | 5 ----- pandas/core/series.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a36298f142cf1..35cebd8a7a525 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10430,11 +10430,6 @@ def corr( DataFrame Correlation matrix. - .. note:: - - Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method. - ``corr`` automatically considers values with matching indices. - See Also -------- DataFrame.corrwith : Compute pairwise correlation with another diff --git a/pandas/core/series.py b/pandas/core/series.py index e59a4cfc3fcc1..cc4eae791712e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2769,6 +2769,10 @@ def corr( float Correlation with other. + .. note:: + Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method. + ``corr`` automatically considers values with matching indices. + See Also -------- DataFrame.corr : Compute pairwise correlation between columns. @@ -2792,6 +2796,12 @@ def corr( >>> s2 = pd.Series([.3, .6, .0, .1]) >>> s1.corr(s2, method=histogram_intersection) 0.3 + + Pandas auto-aligns the values with matching indices + + >>> s1 = pd.Series([1, 2, 3], index=[0, 1, 2]) + >>> s2 = pd.Series([1, 2, 3], index=[2, 1, 0]) + -1.0 """ # noqa: E501 this, other = self.align(other, join="inner", copy=False) if len(this) == 0: From 997be099c4b2977490b1fde7d0f726874ad5035f Mon Sep 17 00:00:00 2001 From: Rajat Subhra Mukherjee Date: Wed, 5 Jul 2023 16:52:28 +0530 Subject: [PATCH 4/7] Update frame.py --- pandas/core/frame.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 35cebd8a7a525..ae43a44d68f1c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10438,7 +10438,6 @@ def corr( Notes ----- - Pearson, Kendall and Spearman correlation are currently computed using pairwise complete observations. * `Pearson correlation coefficient `_ From 4d306b64ff92aa0520357625dc51251fb22e31d1 Mon Sep 17 00:00:00 2001 From: Rajat Subhra Mukherjee Date: Wed, 5 Jul 2023 17:37:14 +0530 Subject: [PATCH 5/7] Added operation in example --- pandas/core/series.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index cc4eae791712e..2d265e3de783b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2801,6 +2801,7 @@ def corr( >>> s1 = pd.Series([1, 2, 3], index=[0, 1, 2]) >>> s2 = pd.Series([1, 2, 3], index=[2, 1, 0]) + >>> s1.corr(s2) -1.0 """ # noqa: E501 this, other = self.align(other, join="inner", copy=False) From fe1026856e25cf2bfcb95871d04b30dc0b47da63 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Wed, 5 Jul 2023 14:08:53 +0000 Subject: [PATCH 6/7] Fixed indentation error for note --- pandas/core/series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 2d265e3de783b..e21d6de85656a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2769,7 +2769,8 @@ def corr( float Correlation with other. - .. note:: + .. note:: + Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method. ``corr`` automatically considers values with matching indices. From 472ab35c6cd9847a9dea33fbd4ad816947de31b5 Mon Sep 17 00:00:00 2001 From: RajatS Mukherjee Date: Wed, 5 Jul 2023 14:20:13 +0000 Subject: [PATCH 7/7] Relocated notes --- pandas/core/series.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index e21d6de85656a..164b1a61b006c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2769,11 +2769,6 @@ def corr( float Correlation with other. - .. note:: - - Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method. - ``corr`` automatically considers values with matching indices. - See Also -------- DataFrame.corr : Compute pairwise correlation between columns. @@ -2788,6 +2783,9 @@ def corr( * `Kendall rank correlation coefficient `_ * `Spearman's rank correlation coefficient `_ + Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method. + ``corr()`` automatically considers values with matching indices. + Examples -------- >>> def histogram_intersection(a, b):