[Python] Counting occurrences of event B that occur between occurrences of event A in Python

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    I am attempting to summarize data in an event log. I have 2 event I want to track. Even A and Event B. I would like to count how many times event B occurs in between occurrences of event A. for example:

    Date Time Event
    0 2025-02-01 03:51:40 A
    1 2025-02-01 05:53:31 B
    2 2025-02-01 07:55:05 B
    3 2025-02-01 10:14:52 B
    4 2025-02-01 12:17:01 A
    5 2025-02-01 14:20:15 B
    6 2025-02-01 20:26:04 A
    7 2025-02-01 22:31:27 A
    8 2025-02-02 03:50:48 B
    9 2025-02-02 05:52:28 B
    10 2025-02-02 14:00:45 A


    I would like to return,

    Date Time Event B Count
    0 2025-02-01 03:51:40 A 0
    1 2025-02-01 12:17:01 A 3
    2 2025-02-01 20:26:04 A 1
    3 2025-02-01 22:31:27 A 0
    4 2025-02-02 14:00:45 A 2


    I have no idea how to accomplish this. Any help is appreciated. Also this is my first stack overflow question, so I apologize if I have done/formatted anything wrong.

    Continue reading...

Compartilhe esta Página