[Python] Generate new Column in Dataframe with Modulo of other Column

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to create a new column "Day2" which takes the second digit of column named "Days", so if we have Days equal to 35, we would take the number 5 to be in "Day2", I tried this but it's not working:

    DF["Day2"] = DF["Days"].where(
    DF["Days"] < 10,
    (DF["Days"] / 10 % 10).astype(int),
    )


    It seems it's taking the first digit but never the second one, can someone help?

    Continue reading...

Compartilhe esta Página