Example
a1 = [1,2,3,4,5]
a2 = [2,3,5,6]
How to calculate correlation coefficient of this types of columns
CodePudding user response:
Trimming the lists to a common length and using numpy.corrcoeff
:
a1 = [1,2,3,4,5]
a2 = [2,3,5,6]
n = min(len(a1), len(a2))
r = np.corrcoef(a1[:n], a2[:n])[0, 1]
Output: 0.9899494936611666