Signup/Sign In
PUBLISHED ON: MAY 3, 2021

Python pandas Series.corr() Method

In this tutorial, we will discuss and learn the Python pandas Series.corr() method. We know that correlation is the measure of the linear relationship between the two variables and using this method, we can find the correlation of the Series with the Series. It returns a float element which is between 1 and -1. Integer 1 indicates a strong positive relationship and integer -1 indicates a strong negative relationship.

The below shows the syntax of the Series.corr() method.

Syntax

Series.corr(other, method='pearson', min_periods=None)

Parameters

other: It is the Series with which to compute the correlation.

method: It includes ‘pearson’, ‘kendall’, ‘spearman’ or callable

Example: Finding correlation of two Series

The below example shows how to find the correlation between the columns of the dataframe using the pearson method.

#importing pandas as pd
import pandas as pd
#importing numpy as np
import numpy as np
series_1 = pd.Series([2,np.nan,4,6])
series_2 = pd.Series([4,6,np.nan,8])
print(series_1.corr(series_2,method='pearson'))


0.9999999999999999

Example: Finding correlation of the Series with the other Series using kendall method

The below example shows how to find the correlation between the columns of the dataframe using the kendall method.

#importing pandas as pd
import pandas as pd
#importing numpy as np
import numpy as np
series_1 = pd.Series([2,np.nan,4,6])
series_2 = pd.Series([4,6,np.nan,8])
print(series_1.corr(series_2,method='kendall'))


1.0

Example: Finding correlation of the Series with the other Series using the spearman method

The below example shows how to find the correlation between the columns of the dataframe using the spearman method.

#importing pandas as pd
import pandas as pd
#importing numpy as np
import numpy as np
series_1 = pd.Series([2,np.nan,4,6])
series_2 = pd.Series([4,6,np.nan,8])
print(series_1.corr(series_2,method='spearman'))


0.9999999999999999

Conclusion

In this tutorial, we learned the python pandas Series.corr() method. We find the correlation of the Series with the other Series elements using the Pearson, Kendall, spearman methods.



About the author:
I like writing about Python, and frameworks like Pandas, Numpy, Scikit, etc. I am still learning Python. I like sharing what I learn with others through my content.