Skip to content

Commit 6725e37

Browse files
DOC: fix PR02 errors in docstring for pandas.core.groupby.DataFrameGroupBy.corrwith (#57243)
* DOC: fix PR02 errors in docstring for pandas.core.groupby.DataFrameGroupBy.corrwith * updated code example for groupby(...).corrwith
1 parent 17aa2ba commit 6725e37

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
151151
pandas.core.groupby.SeriesGroupBy.rolling\
152152
pandas.core.groupby.DataFrameGroupBy.hist\
153153
pandas.core.groupby.DataFrameGroupBy.plot\
154-
pandas.core.groupby.DataFrameGroupBy.corrwith\
155154
pandas.core.groupby.SeriesGroupBy.plot # There should be no backslash in the final line, please keep this comment in the last ignored function
156155
RET=$(($RET + $?)) ; echo $MSG "DONE"
157156

pandas/core/frame.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -11060,8 +11060,10 @@ def corrwith(
1106011060
--------
1106111061
>>> index = ["a", "b", "c", "d", "e"]
1106211062
>>> columns = ["one", "two", "three", "four"]
11063-
>>> df1 = pd.DataFrame(np.arange(20).reshape(5, 4), index=index, columns=columns)
11064-
>>> df2 = pd.DataFrame(np.arange(16).reshape(4, 4), index=index[:4], columns=columns)
11063+
>>> df1 = pd.DataFrame(np.arange(20).reshape(5, 4),
11064+
... index=index, columns=columns)
11065+
>>> df2 = pd.DataFrame(np.arange(16).reshape(4, 4),
11066+
... index=index[:4], columns=columns)
1106511067
>>> df1.corrwith(df2)
1106611068
one 1.0
1106711069
two 1.0
@@ -11076,7 +11078,7 @@ def corrwith(
1107611078
d 1.0
1107711079
e NaN
1107811080
dtype: float64
11079-
""" # noqa: E501
11081+
"""
1108011082
axis = self._get_axis_number(axis)
1108111083
this = self._get_numeric_data() if numeric_only else self
1108211084

pandas/core/groupby/generic.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -2491,14 +2491,67 @@ def dtypes(self) -> Series:
24912491
lambda df: df.dtypes, self._selected_obj
24922492
)
24932493

2494-
@doc(DataFrame.corrwith.__doc__)
24952494
def corrwith(
24962495
self,
24972496
other: DataFrame | Series,
24982497
drop: bool = False,
24992498
method: CorrelationMethod = "pearson",
25002499
numeric_only: bool = False,
25012500
) -> DataFrame:
2501+
"""
2502+
Compute pairwise correlation.
2503+
2504+
Pairwise correlation is computed between rows or columns of
2505+
DataFrame with rows or columns of Series or DataFrame. DataFrames
2506+
are first aligned along both axes before computing the
2507+
correlations.
2508+
2509+
Parameters
2510+
----------
2511+
other : DataFrame, Series
2512+
Object with which to compute correlations.
2513+
drop : bool, default False
2514+
Drop missing indices from result.
2515+
method : {'pearson', 'kendall', 'spearman'} or callable
2516+
Method of correlation:
2517+
2518+
* pearson : standard correlation coefficient
2519+
* kendall : Kendall Tau correlation coefficient
2520+
* spearman : Spearman rank correlation
2521+
* callable: callable with input two 1d ndarrays
2522+
and returning a float.
2523+
2524+
numeric_only : bool, default False
2525+
Include only `float`, `int` or `boolean` data.
2526+
2527+
.. versionadded:: 1.5.0
2528+
2529+
.. versionchanged:: 2.0.0
2530+
The default value of ``numeric_only`` is now ``False``.
2531+
2532+
Returns
2533+
-------
2534+
Series
2535+
Pairwise correlations.
2536+
2537+
See Also
2538+
--------
2539+
DataFrame.corr : Compute pairwise correlation of columns.
2540+
2541+
Examples
2542+
--------
2543+
>>> df1 = pd.DataFrame({"Day": [1, 1, 1, 2, 2, 2, 3, 3, 3],
2544+
... "Data": [6, 6, 8, 5, 4, 2, 7, 3, 9]})
2545+
>>> df2 = pd.DataFrame({"Day": [1, 1, 1, 2, 2, 2, 3, 3, 3],
2546+
... "Data": [5, 3, 8, 3, 1, 1, 2, 3, 6]})
2547+
2548+
>>> df1.groupby("Day").corrwith(df2)
2549+
Data Day
2550+
Day
2551+
1 0.917663 NaN
2552+
2 0.755929 NaN
2553+
3 0.576557 NaN
2554+
"""
25022555
result = self._op_via_apply(
25032556
"corrwith",
25042557
other=other,

0 commit comments

Comments
 (0)