[Python] creating cols from cols that are being created within the same `with_columns` method

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    Here col "AB" is just being create and at the same time is being used as input to create col "ABC". This fails.

    df = df.with_columns(
    (pl.col("A")+pl.col("B")).alias("AB"),
    (pl.col("AB")+pl.col("C")).alias("ABC")
    )


    Or the only way to do this is just using a second with_columns method.

    df1 = df.with_columns(
    (pl.col("A")+pl.col("B")).alias("AB")
    )
    df2 = df1.with_columns(
    (pl.col("AB")+pl.col("C")).alias("ABC")
    )

    Continue reading...

Compartilhe esta Página