Skip to content

Commit

Permalink
Add correlation transform (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Jul 24, 2024
1 parent b9712d9 commit 84858f9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lumen/transforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,31 @@ def apply(self, table: DataFrame) -> DataFrame:
return table.dropna(**kwargs)


class Corr(Transform):
"""
``Corr`` computes pairwise correlation of columns, excluding NA/null values.
"""

method = param.Selector(default='pearson', objects=[
'pearson', 'kendall', 'spearman'], doc="""
Method of correlation.""")

min_periods = param.Integer(default=1, doc="""
Minimum number of observations required per pair of columns
to have a valid result. Currently only available for Pearson
and Spearman correlation.""")

numeric_only = param.Boolean(default=False, doc="""
Include only `float`, `int` or `boolean` data.""")

transform_type: ClassVar[str] = 'corr'

def apply(self, table: DataFrame) -> DataFrame:
return table.corr(
method=self.method, min_periods=self.min_periods, numeric_only=self.numeric_only
)


class project_lnglat(Transform):
"""
`project_lnglat` projects the given longitude/latitude columns to Web Mercator.
Expand Down

0 comments on commit 84858f9

Please sign in to comment.