Skip to content

docs: add code samples for Series.corr #316

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

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 0 additions & 20 deletions bigframes/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,26 +735,6 @@ def round(self, decimals=0) -> "Series":
return self._apply_binary_op(decimals, ops.round_op)

def corr(self, other: Series, method="pearson", min_periods=None) -> float:
"""
Compute the correlation with the other Series. Non-number values are ignored in the
computation.

Uses the "Pearson" method of correlation. Numbers are converted to float before
calculation, so the result may be unstable.

Args:
other (Series):
The series with which this is to be correlated.
method (string, default "pearson"):
Correlation method to use - currently only "pearson" is supported.
min_periods (int, default None):
The minimum number of observations needed to return a result. Non-default values
are not yet supported, so a result will be returned for at least two observations.

Returns:
float; Will return NaN if there are fewer than two numeric pairs, either series has a
variance or covariance of zero, or any input value is infinite.
"""
# TODO(kemppeterson): Validate early that both are numeric
# TODO(kemppeterson): Handle partially-numeric columns
if method != "pearson":
Expand Down
15 changes: 15 additions & 0 deletions third_party/bigframes_vendored/pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,21 @@ def corr(self, other, method="pearson", min_periods=None) -> float:
Uses the "Pearson" method of correlation. Numbers are converted to float before
calculation, so the result may be unstable.

**Examples:**

>>> import bigframes.pandas as bpd
>>> bpd.options.display.progress_bar = None

>>> s1 = bpd.Series([.2, .0, .6, .2])
>>> s2 = bpd.Series([.3, .6, .0, .1])
>>> s1.corr(s2)
-0.8510644963469901

>>> s1 = bpd.Series([1, 2, 3], index=[0, 1, 2])
>>> s2 = bpd.Series([1, 2, 3], index=[2, 1, 0])
>>> s1.corr(s2)
-1.0

Args:
other (Series):
The series with which this is to be correlated.
Expand Down