pandas.core.groupby.DataFrameGroupBy.corrwith#
- DataFrameGroupBy.corrwith(other, drop=False, method='pearson', numeric_only=False)[source]#
Compute pairwise correlation.
Deprecated since version 3.0.0.
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:
- otherDataFrame, Series
Object with which to compute correlations.
- dropbool, 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_onlybool, default False
Include only float, int or boolean data.
Added in version 1.5.0.
Changed in version 2.0.0: The default value of
numeric_only
is nowFalse
.
- 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