Skip to content

Add option for alternative correlation types to DataFrame.corrwith() #21941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Add option for alternative correlation types to DataFrame.corrwith() #21941

wants to merge 1 commit into from

Conversation

samwaterbury
Copy link

@samwaterbury samwaterbury commented Jul 17, 2018

This adds a method argument to DataFrame.corrwith() which calls the corresponding correlation function which already exists within pandas. The default option "pearson" was originally implemented directly in this method, I changed it to match the other options for consistency (and a slight speed improvement).

@gfyoung gfyoung added Enhancement Apply Apply, Aggregate, Transform, Map labels Jul 17, 2018
@@ -6891,7 +6891,7 @@ def cov(self, min_periods=None):

return self._constructor(baseCov, index=idx, columns=cols)

def corrwith(self, other, axis=0, drop=False):
def corrwith(self, other, axis=0, method='pearson', drop=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...it would be safest to add it to the end of the signature, as this modification as it stands is not backwards compatible. Alternatively, you could issue a DeprecationWarning if a boolean is passed to method and re-assign it to drop.

@mroeschke
Copy link
Member

The default option "pearson" was originally implemented directly in this method, I changed it to match the other options for consistency (and a slight speed improvement)

Could you demonstrate this speed improvement with the ASV? I am a little dubious that the iterative method is more performant than the existing implementation.

@samwaterbury samwaterbury deleted the corrwith-changes branch August 5, 2018 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow different methods of correlation when using corrwith
3 participants