[Python] Create a True/False column based on a sequence of numbers in another column with...

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I want to add a Momentum column to my df that takes True when I have three or more consecutive possessions and False otherwise.

    I have this:

    event seconds_since_start_of_game possessions
    FOUL_RECEIVE 49.0 1.0
    FOUL_RECEIVE 73.0 1.0
    POST_OUT 86.0 1.0
    LOST_BALL 101.0 1.0
    2MIN_PROVOKE 122.0 2.0
    FOUL_RECEIVE 137.0 2.0
    POST_OUT 148.0 2.0
    POST_OUT 306.0 4.0
    LOST_BALL 324.0 5.0
    FOUL_RECEIVE 362.0 6.0
    LOST_BALL 376.0 6.0
    FOUL_RECEIVE 399.0 7.0

    and I want that:

    event seconds_since_start_of_game possessions momentum
    FOUL_RECEIVE 49.0 1.0 False
    FOUL_RECEIVE 73.0 1.0 False
    POST_OUT 86.0 1.0 False
    LOST_BALL 101.0 1.0 False
    2MIN_PROVOKE 122.0 2.0 False
    FOUL_RECEIVE 137.0 2.0 False
    POST_OUT 148.0 2.0 False
    POST_OUT 306.0 4.0 True
    LOST_BALL 324.0 5.0 True
    FOUL_RECEIVE 362.0 6.0 True
    LOST_BALL 376.0 6.0 True
    FOUL_RECEIVE 399.0 7.0 True

    Continue reading...

Compartilhe esta Página