[Python] Extract the max of a cumulative sum from dataframe column

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    I have a dataframe column containing values of 0 and 1. Values of 0 indicate a piece of equipment is off line while 1 indicates the equipment is running. To calculate the days online between outages I used:

    df['col2'] = df[col1].groupby(df_proc[col1].eq(0).cumsum()).cumcount()

    df['col2'] contains a cumulative total of the days online between outages.

    Example:

    Dataframe

    I need to extract the date and the cumumlative total before each of the outages into a separate dataframe. From the example above I would want:

    Date DaysOnline
    6/2/2025 4
    6/10/2025 5

    I obviously am a novice at Python and StackOverflow. Any help would be appreciated.

    Continue reading...

Compartilhe esta Página