Skip to content
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

feat(python): add dataframe.pearson_corr #5533

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions py-polars/polars/internals/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math
import os
import sys
import typing
from collections.abc import Sized
from datetime import timedelta
from io import BytesIO, IOBase, StringIO
Expand Down Expand Up @@ -6629,6 +6630,28 @@ def unnest(self: DF, names: str | Sequence[str]) -> DF:
names = [names]
return self._from_pydf(self._df.unnest(names))

@typing.no_type_check
def pearson_corr(self, **kwargs: dict[str, Any]) -> DataFrame:
"""
Return Pearson product-moment correlation coefficients.

See numpy corrcoef for more information.

Notes
-----
This functionality requires numpy to be installed.

Parameters
----------
kwargs
keyword arguments are passed to numpy corrcoef

"""
return DataFrame(
np.corrcoef(self, **kwargs),
columns=self.columns,
)


def _prepare_other_arg(other: Any) -> pli.Series:
# if not a series create singleton series such that it will broadcast
Expand Down