Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.corr#

DataFrame.corr(method='pearson',min_periods=1,numeric_only=False)[source]#

Compute pairwise correlation of columns, excluding NA/null values.

Parameters:
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. Note that the returned matrix from corrwill have 1 along the diagonals and will be symmetricregardless of the callable’s behavior.

min_periodsint, optional

Minimum number of observations required per pair of columnsto have a valid result. Currently only available for Pearsonand Spearman correlation.

numeric_onlybool, default False

Include onlyfloat,int orboolean data.

Added in version 1.5.0.

Changed in version 2.0.0:The default value ofnumeric_only is nowFalse.

Returns:
DataFrame

Correlation matrix.

See also

DataFrame.corrwith

Compute pairwise correlation with another DataFrame or Series.

Series.corr

Compute the correlation between two Series.

Notes

Pearson, Kendall and Spearman correlation are currently computed using pairwise complete observations.

Examples

>>>defhistogram_intersection(a,b):...v=np.minimum(a,b).sum().round(decimals=1)...returnv>>>df=pd.DataFrame([(.2,.3),(.0,.6),(.6,.0),(.2,.1)],...columns=['dogs','cats'])>>>df.corr(method=histogram_intersection)      dogs  catsdogs   1.0   0.3cats   0.3   1.0
>>>df=pd.DataFrame([(1,1),(2,np.nan),(np.nan,3),(4,4)],...columns=['dogs','cats'])>>>df.corr(min_periods=3)      dogs  catsdogs   1.0   NaNcats   NaN   1.0

[8]ページ先頭

©2009-2025 Movatter.jp