# How to determine Spearman’s correlation in Python

Spearman’s correlation, also known as rank correlation, is a statistical method that is used to measure the strength of a monotonic relationship between two variables. It ranges from -1 to 1, where -1 indicates a strong negative correlation, 0 indicates no correlation, and 1 indicates a strong positive correlation. In Python, we can calculate Spearman’s correlation coefficient using the `scipy`

library.

```
from scipy.stats import spearmanr
// Create some sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 4, 5, 6]
// Calculate the Spearman's correlation coefficient
corr, p_value = spearmanr(x, y)
print("Spearman's correlation coefficient:", corr)
```

This will output:

`Spearman's correlation coefficient: 1.0`

Here, `spearmanr()`

function takes in two arrays as input: x and y and returns two values: correlation coefficient and p-value. Correlation coefficient will be between -1 and 1 and p-value will be a probability score which helps to determine the significance of the correlation.

In this example, we get a correlation coefficient of 1 which indicates a strong positive correlation between x and y.

It’s important to note that, Spearman’s correlation measure the rank correlation, which means the correlation between the ranks of two variables instead of the actual values. It is useful when you have ordinal data or when the relationship between two variables is non-linear. It’s also important to check for outliers and missing values before calculating correlation coefficients.

In simple words, Spearman’s correlation coefficient is a statistical method that helps to measure the strength of the monotonic relationship between two variables. In python, we can calculate Spearman’s correlation coefficient using the scipy library’s `spearmanr()`

function. It will give correlation coefficient and p-value as output, which helps to determine the significance of correlation between two variables.

In this Learn through Codes example, you will learn: How to determine Spearman’s correlation in Python.

### Essential Gigs

**Nilimesh: I will develop time series forecasting model for you using python or r for $50 on…**

*For only $50, Nilimesh will develop time series forecasting model for you using python or r. | Note: please contact me…*www.fiverr.com

**Nilimesh: I will do your data analytics and econometrics projects in python for $50 on fiverr.com**

*For only $50, Nilimesh will do your data analytics and econometrics projects in python. | Note: please contact me…*www.fiverr.com

**Nilimesh: I will do your machine learning and data science projects in python for $50 on fiverr.com**

*For only $50, Nilimesh will do your machine learning and data science projects in python. | Note: please contact me…*www.fiverr.com

**Nilimesh: I will do your gis and spatial programming projects in python for $50 on fiverr.com**

*For only $50, Nilimesh will do your gis and spatial programming projects in python. | Note: please contact me before…*www.fiverr.com