From 84858f9a416e8a07a39654c6227d2529fbb84fbf Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 24 Jul 2024 16:40:59 +0200 Subject: [PATCH] Add correlation transform (#614) --- lumen/transforms/base.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lumen/transforms/base.py b/lumen/transforms/base.py index 8603b613c..41f53c50a 100644 --- a/lumen/transforms/base.py +++ b/lumen/transforms/base.py @@ -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.