Skip to content

CorrelationWith

Base classes

Name Children Inherits
CallOp
datacook.engine.ops.base
An op that is one pandas call.

⋔ Inheritance diagram

graph TD
  2130721889["stats.CorrelationWith"]
  3484306131["base.CallOp"]
  1539482213["base.Op"]
  2751680898["builtins.object"]
  3484306131 --> 2130721889
  1539482213 --> 3484306131
  2751680898 --> 1539482213

🛈 DocStrings

Bases: CallOp

df.corrwith(other): columns matched by name, rows by position (no index).

Pearson only: pandas computes Spearman / Kendall here with scipy (no dependency).

Source code in src/datacook/engine/ops/stats.py
class CorrelationWith(base.CallOp):
    """`df.corrwith(other)`: columns matched by name, rows by position (no index).

    Pearson only: pandas computes Spearman / Kendall here with scipy (no dependency).
    """

    id = "corrwith"
    title = _("Correlation with another table")
    description = _(
        "Pearson correlation of each column with the column of the same name in a second"
        " table (rows matched by position)."
    )
    category = categories.STATS
    icon = "mdi.chart-scatter-plot"
    n_inputs = 2
    method = "corrwith"
    always = ("numeric_only",)
    then = '.rename_axis("column").reset_index(name="correlation")'

    class Params(base.Params):
        drop: bool = Field(False, title=N_("Drop columns missing in one table"))
        numeric_only: bool = _numeric_only()

    @classmethod
    def finish(cls, params: Any, result: Any) -> Any:
        return result.rename_axis("column").reset_index(name="correlation")

:fa-brands-github: Show source on GitHub