Pandas Series: corr() function
Compute correlation
The corr() function is used to compute correlation with other Series, excluding missing values.
Syntax:
Series.corr(self, other, method='pearson', min_periods=None)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
other | Series with which to compute the correlation. | Series | Required |
method |
|
{‘pearson’, ‘kendall’, ‘spearman’} or callable | Required |
min_periods | Minimum number of observations needed to have a valid result. | int | Optional |
Returns: float
Correlation with other.
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
def histogram_intersection(p, q):
v = np.minimum(p, q).sum().round(decimals=1)
return v
s1 = pd.Series([.1, .0, .5, .1])
s2 = pd.Series([.2, .3, .0, .2])
s1.corr(s2, method=histogram_intersection)
Output:
0.2
Previous: Trim values at input in Pandas
Next: Count null observations in Pandas series
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook