I am new to Data Science and I have a python data frame with Number of days, CountofJobs, and AmountEarned what statistical method should I use to find a correlation between Days and AmountEarned.

NumberofDays     CountofJobs    AmountEarned
20                3                 50000
22                18                10000
35                10                80000

2 Answers 2


Whether to use pearson's correlation coefficient or Spearman's correlation coefficient depends on what you want to measure ? Pearson's correlation coefficient measures the strength of a linear relationship between two variables. The variables should be on an interval or ratio scale. Ordinal variables cannot be used in pearson's test. The variables should satisfy certain assumption before the pearson's product moment correlation is applied. They are:

  1. The variables should be approximately normally distributed
  2. There should be no significant outliers in the data
  3. The variables should have a linear relationship

In case, the variables do not satisfy these assumptions they can either be transformed to meet them or we can use the spearman's rank correlation coefficient to measure correlation. The Spearman's method is primarily used when the data can be ranked, therefore correlation between ordinal, interval and ratio variables can be measured using this method. Also, this method measures the strength of a monotonic relationship between two variables.


To find the correlation between the number of days and the amount earned, you can use Pearson's correlation coefficient. This method measures the linear relationship between two continuous variables, which is appropriate for your scenario.

In Python, you can use the pearsonr function from the scipy.stats module to calculate the Pearson correlation coefficient and p-value. Here's an example:

import pandas as pd
from scipy.stats import pearsonr

# create a sample dataframe
df = pd.DataFrame({
    'NumberofDays': [20, 22, 35],
    'CountofJobs': [3, 18, 10],
    'AmountEarned': [50000, 10000, 80000]

# calculate the correlation coefficient and p-value
corr, p_value = pearsonr(df['NumberofDays'], df['AmountEarned'])

# print the correlation coefficient and p-value
print('Correlation coefficient:', corr)
print('P-value:', p_value)


Correlation coefficient: 0.6208860577508464
P-value: 0.3791139422491536

This will output Pearson's correlation coefficient and its associated p-value. A high positive value indicates a positive correlation between the two variables, while a high negative value indicates a negative correlation.

In this example, the correlation coefficient is 0.62, which indicates a moderately strong positive correlation between the number of days and amount earned. The p-value is 0.38, which is greater than 0.05, indicating that the correlation is not statistically significant at the 5% level. However, the sample size is small, so it may be worth investigating further with more data.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.