- API reference
- DataFrame
- pandas.DataF...
pandas.DataFrame.corrwith#
- DataFrame.corrwith(other,axis=0,drop=False,method='pearson',numeric_only=False)[source]#
Compute pairwise correlation.
Pairwise correlation is computed between rows or columns ofDataFrame with rows or columns of Series or DataFrame. DataFramesare first aligned along both axes before computing thecorrelations.
- Parameters:
- otherDataFrame, Series
Object with which to compute correlations.
- axis{0 or ‘index’, 1 or ‘columns’}, default 0
The axis to use. 0 or ‘index’ to compute row-wise, 1 or ‘columns’ forcolumn-wise.
- 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 onlyfloat,int orboolean data.
Added in version 1.5.0.
Changed in version 2.0.0:The default value of
numeric_onlyis nowFalse.
- Returns:
- Series
Pairwise correlations.
See also
DataFrame.corrCompute pairwise correlation of columns.
Examples
>>>index=["a","b","c","d","e"]>>>columns=["one","two","three","four"]>>>df1=pd.DataFrame(np.arange(20).reshape(5,4),index=index,columns=columns)>>>df2=pd.DataFrame(np.arange(16).reshape(4,4),index=index[:4],columns=columns)>>>df1.corrwith(df2)one 1.0two 1.0three 1.0four 1.0dtype: float64
>>>df2.corrwith(df1,axis=1)a 1.0b 1.0c 1.0d 1.0e NaNdtype: float64