Juan Carlos Zazueta
Juan Carlos Zazueta

Reputation: 1

Where is the code for correlation in pandas?

I am working with anaconda and looking for the code for the correlation matrix in pandas. I look into /pandas/core/frame.py and found

from pandas._libs import algos as libalgos, lib, properties

several lines after I found:

def corr(self, method="pearson", min_periods=1) -> "DataFrame":

this uses correl from libalgos

if method == "pearson":
    correl = libalgos.nancorr(mat, minp=min_periods)

But when I look in ../pandas/lib/ there is not algos library.

My question is the libalgos.nacorr is compiled in C and where is the code.

Upvotes: 0

Views: 1350

Answers (1)

mCoding
mCoding

Reputation: 4869

The method you are looking for is in the DataFrame class. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.corr.html

DataFrame.corr(method='pearson', min_periods=1)

If you are looking for the actual nancorr source, see here: https://github.com/pandas-dev/pandas/blob/d4cd068ae278d2a37788363df48f687ee1baceba/pandas/_libs/algos.pyx

Upvotes: 1

Related Questions