[Python] Selecting rows in pandas dataframe that contain same id and were created within 1...

Discussão em 'Python' iniciado por Stack, Junho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I have a pandas dataframe that contains multiple rows with one identificator and the datetime of the row.

    id creation_date
    MP5694319-001 2024-05-29 12:58:00.489
    MP5694319-001 2024-05-29 12:58:03.489
    MP5694331-001 2024-05-29 12:58:05.489
    MP5694319-001 2024-05-29 13:03:03.489

    From this dataframe I need to filter rows that contain both the same id and were created within 1 minute from each other. The final result:

    id creation_date
    MP5694319-001 2024-05-29 12:58:00.489
    MP5694319-001 2024-05-29 12:58:03.489

    Dataframe contains multiple rows with various id, so I need to group them somehow and then apply the difference, but I have no idea how to do this.

    Continue reading...

Compartilhe esta Página