Skip to content

Commit 9150c16

Browse files
authored
docs: add code samples for Series.corr (#316)
1 parent 4a1a1e0 commit 9150c16

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

bigframes/series.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -735,26 +735,6 @@ def round(self, decimals=0) -> "Series":
735735
return self._apply_binary_op(decimals, ops.round_op)
736736

737737
def corr(self, other: Series, method="pearson", min_periods=None) -> float:
738-
"""
739-
Compute the correlation with the other Series. Non-number values are ignored in the
740-
computation.
741-
742-
Uses the "Pearson" method of correlation. Numbers are converted to float before
743-
calculation, so the result may be unstable.
744-
745-
Args:
746-
other (Series):
747-
The series with which this is to be correlated.
748-
method (string, default "pearson"):
749-
Correlation method to use - currently only "pearson" is supported.
750-
min_periods (int, default None):
751-
The minimum number of observations needed to return a result. Non-default values
752-
are not yet supported, so a result will be returned for at least two observations.
753-
754-
Returns:
755-
float; Will return NaN if there are fewer than two numeric pairs, either series has a
756-
variance or covariance of zero, or any input value is infinite.
757-
"""
758738
# TODO(kemppeterson): Validate early that both are numeric
759739
# TODO(kemppeterson): Handle partially-numeric columns
760740
if method != "pearson":

third_party/bigframes_vendored/pandas/core/series.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,21 @@ def corr(self, other, method="pearson", min_periods=None) -> float:
809809
Uses the "Pearson" method of correlation. Numbers are converted to float before
810810
calculation, so the result may be unstable.
811811
812+
**Examples:**
813+
814+
>>> import bigframes.pandas as bpd
815+
>>> bpd.options.display.progress_bar = None
816+
817+
>>> s1 = bpd.Series([.2, .0, .6, .2])
818+
>>> s2 = bpd.Series([.3, .6, .0, .1])
819+
>>> s1.corr(s2)
820+
-0.8510644963469901
821+
822+
>>> s1 = bpd.Series([1, 2, 3], index=[0, 1, 2])
823+
>>> s2 = bpd.Series([1, 2, 3], index=[2, 1, 0])
824+
>>> s1.corr(s2)
825+
-1.0
826+
812827
Args:
813828
other (Series):
814829
The series with which this is to be correlated.

0 commit comments

Comments
 (0)