1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Corr of one column with all other numeric ones

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 20:32.

  1. Stack

    Stack Membro Participativo

    Starting with

    import polars as pl
    df = pl.DataFrame({
    'a': [1,2,3],
    'b': [4.,2.,6.],
    'c': ['w', 'a', 'r'],
    'd': [4, 1, 1]
    })


    how can I get the correlation between a and all other numeric columns?

    Equivalent in pandas:

    In [30]: (
    ...: pd.DataFrame({
    ...: 'a': [1,2,3],
    ...: 'b': [4.,2.,6.],
    ...: 'c': ['w', 'a', 'r'],
    ...: 'd': [4, 1, 1]
    ...: })
    ...: .corr()
    ...: .loc['a']
    ...: )
    Out[30]:
    a 1.000000
    b 0.500000
    d -0.866025
    Name: a, dtype: float64


    I've tried

    (
    df.select(pl.col(pl.Int64).cast(pl.Float64), pl.col(pl.Float64))
    .select(pl.corr('a', pl.exclude('a')))
    )


    but got

    DuplicateError: the name 'a' is duplicate

    Continue reading...

Compartilhe esta Página