Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into sty/ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Feb 6, 2024
2 parents 65c4c33 + 6725e37 commit 6fbe5ca
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.core.groupby.SeriesGroupBy.rolling\
pandas.core.groupby.DataFrameGroupBy.hist\
pandas.core.groupby.DataFrameGroupBy.plot\
pandas.core.groupby.DataFrameGroupBy.corrwith\
pandas.core.groupby.SeriesGroupBy.plot # There should be no backslash in the final line, please keep this comment in the last ignored function
RET=$(($RET + $?)) ; echo $MSG "DONE"

Expand Down
63 changes: 62 additions & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2544,14 +2544,75 @@ def dtypes(self) -> Series:
lambda df: df.dtypes, self._selected_obj
)

@doc(DataFrame.corrwith.__doc__)
def corrwith(
self,
other: DataFrame | Series,
drop: bool = False,
method: CorrelationMethod = "pearson",
numeric_only: bool = False,
) -> DataFrame:
"""
Compute pairwise correlation.
Pairwise correlation is computed between rows or columns of
DataFrame with rows or columns of Series or DataFrame. DataFrames
are first aligned along both axes before computing the
correlations.
Parameters
----------
other : DataFrame, Series
Object with which to compute correlations.
drop : bool, default False
Drop missing indices from result.
method : {'pearson', 'kendall', 'spearman'} or callable
Method of correlation:
* pearson : standard correlation coefficient
* kendall : Kendall Tau correlation coefficient
* spearman : Spearman rank correlation
* callable: callable with input two 1d ndarrays
and returning a float.
numeric_only : bool, default False
Include only `float`, `int` or `boolean` data.
.. versionadded:: 1.5.0
.. versionchanged:: 2.0.0
The default value of ``numeric_only`` is now ``False``.
Returns
-------
Series
Pairwise correlations.
See Also
--------
DataFrame.corr : Compute pairwise correlation of columns.
Examples
--------
>>> df1 = pd.DataFrame(
... {
... "Day": [1, 1, 1, 2, 2, 2, 3, 3, 3],
... "Data": [6, 6, 8, 5, 4, 2, 7, 3, 9],
... }
... )
>>> df2 = pd.DataFrame(
... {
... "Day": [1, 1, 1, 2, 2, 2, 3, 3, 3],
... "Data": [5, 3, 8, 3, 1, 1, 2, 3, 6],
... }
... )
>>> df1.groupby("Day").corrwith(df2)
Data Day
Day
1 0.917663 NaN
2 0.755929 NaN
3 0.576557 NaN
"""
result = self._op_via_apply(
"corrwith",
other=other,
Expand Down

0 comments on commit 6fbe5ca

Please sign in to comment.