From 61715da87ba1eafe41b22a535fdc833fb0724ff8 Mon Sep 17 00:00:00 2001 From: Rajat Subhra Mukherjee Date: Wed, 5 Jul 2023 22:51:00 +0530 Subject: [PATCH] DOC: Added note for `corr` (#53972) * Added note for corr * Removed additional linebreak * Added example and note for Series.corr * Update frame.py * Added operation in example * Fixed indentation error for note * Relocated notes --- pandas/core/series.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index e59a4cfc3fcc1..164b1a61b006c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2783,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): @@ -2792,6 +2795,13 @@ 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]) + >>> s1.corr(s2) + -1.0 """ # noqa: E501 this, other = self.align(other, join="inner", copy=False) if len(this) == 0: