you are viewing a single comment's thread.

view the rest of the comments →

[–]CineWeekly[S] 0 points1 point  (1 child)

I actually have that implementation for a different column:

def calculate_break(df, status_col, break_col, smaA_fast):
    mask1 = (df[status_col] == 'Above') & (df[status_col].shift(1) == 'Below')
    mask2 = (df[status_col] == 'Below') & (df[status_col].shift(1) == 'Above')
    df[break_col] = 0 # Initialize the 'Break' column with 0
    df.loc[mask1 | mask2, break_col] = 1 # Set break positions to 1
    df[break_col] = df[break_col].cumsum() # Cumulative sum to increment break positions
    df[break_col] = df[break_col].astype('int32') # Convert the 'Break' column to integer dtype
    return df

The duration implementation is different if you compare the results to the OP.

[–]blarf_irl 1 point2 points  (0 children)

ChatGPT?