How to find correlation between two variables using kendal method in python?

Description

To find correlation using kendal
method using python.

  Import kendal method from 
scipy.stats.

  Load the sample data set.

  Pass the arguments x and y 
to the kendal().

#import pandas library

import pandas as pd

#import kendal method from scipy.stats

from scipy.stats import kendalltau

#load sample data

data={‘salary':[1000,200,300,400

,50,400,300,2000,100,50],

‘age':[25,26,25,23,30,29,23,23,25,25],

‘rating':[4,3.24,2.5,2.25,2,2.25,2.5,2.75,

3.2,4.2], ‘bonus':[2500,1200,900,3000,

1800,1400,850,250,750,1000]}

#create and store the data into a data frame

df=pd.DataFrame(data)

print(“Actual Data frame\n”,df)

#pass the arguments to kendal()

p=kendalltau(df[‘salary’],df[‘age’])

q=kendalltau(df[‘rating’],df[‘bonus’])

#print the results

print(p)

print(q)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit