Skip to content

Commit a85c5c7

Browse files
committed
DOC: change corr docstring to inline from @doc for SeriesGroupBy
1 parent 3ac1822 commit a85c5c7

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

pandas/core/groupby/generic.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,13 +2194,83 @@ def idxmax(self, skipna: bool = True) -> Series:
21942194
"""
21952195
return self._idxmax_idxmin("idxmax", skipna=skipna)
21962196

2197-
@doc(Series.corr.__doc__)
21982197
def corr(
21992198
self,
22002199
other: Series,
22012200
method: CorrelationMethod = "pearson",
22022201
min_periods: int | None = None,
22032202
) -> Series:
2203+
"""
2204+
Compute correlation with `other` Series, excluding missing values.
2205+
2206+
The two `Series` objects are not required to be the same length and will be
2207+
aligned internally before the correlation function is applied.
2208+
2209+
Parameters
2210+
----------
2211+
other : Series
2212+
Series with which to compute the correlation.
2213+
method : {'pearson', 'kendall', 'spearman'} or callable
2214+
Method used to compute correlation:
2215+
2216+
- pearson : Standard correlation coefficient
2217+
- kendall : Kendall Tau correlation coefficient
2218+
- spearman : Spearman rank correlation
2219+
- callable: Callable with input two 1d ndarrays and returning a float.
2220+
2221+
.. warning::
2222+
Note that the returned matrix from corr will have 1 along the
2223+
diagonals and will be symmetric regardless of the callable's
2224+
behavior.
2225+
min_periods : int, optional
2226+
Minimum number of observations needed to have a valid result.
2227+
2228+
Returns
2229+
-------
2230+
float
2231+
Correlation with other.
2232+
2233+
See Also
2234+
--------
2235+
DataFrame.corr : Compute pairwise correlation between columns.
2236+
DataFrame.corrwith : Compute pairwise correlation with another
2237+
DataFrame or Series.
2238+
2239+
Notes
2240+
-----
2241+
Pearson, Kendall and Spearman correlation are currently computed using pairwise complete observations.
2242+
2243+
* `Pearson correlation coefficient <https://en.wikipedia.org/wiki/Pearson_correlation_coefficient>`_
2244+
* `Kendall rank correlation coefficient <https://en.wikipedia.org/wiki/Kendall_rank_correlation_coefficient>`_
2245+
* `Spearman's rank correlation coefficient <https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient>`_
2246+
2247+
Automatic data alignment: as with all pandas operations, automatic data alignment is performed for this method.
2248+
``corr()`` automatically considers values with matching indices.
2249+
2250+
Examples
2251+
--------
2252+
>>> def histogram_intersection(a, b):
2253+
... v = np.minimum(a, b).sum().round(decimals=1)
2254+
... return v
2255+
>>> s1 = pd.Series([0.2, 0.0, 0.6, 0.2])
2256+
>>> s2 = pd.Series([0.3, 0.6, 0.0, 0.1])
2257+
>>> s1.corr(s2, method=histogram_intersection)
2258+
0.3
2259+
2260+
Pandas auto-aligns the values with matching indices
2261+
2262+
>>> s1 = pd.Series([1, 2, 3], index=[0, 1, 2])
2263+
>>> s2 = pd.Series([1, 2, 3], index=[2, 1, 0])
2264+
>>> s1.corr(s2)
2265+
-1.0
2266+
2267+
If the input is a constant array, the correlation is not defined in this case,
2268+
and ``np.nan`` is returned.
2269+
2270+
>>> s1 = pd.Series([0.45, 0.45])
2271+
>>> s1.corr(s1)
2272+
nan
2273+
"""
22042274
result = self._op_via_apply(
22052275
"corr", other=other, method=method, min_periods=min_periods
22062276
)

0 commit comments

Comments
 (0)