Jun-20-2022, 07:06 PM
For future googlers, here's the method I figured out:
df['InputStable'] = df['InputBus'] == df['InputBus'].shift(periods=1, fill_value=0) & df['InputBus'].shift(periods=2, fill_value=0)
This creates a new boolean column, which contains true/false based on whether the current value equals the previous value and the one before that.
I think I'm binary bitwise ANDing two integers here and then comparing that result, which is probably breaking a thousand rules, but it seems to be working just fine in practice.
This utilizes the shift() function in pandas.
I also used drop() and drop_duplicates() to get rid repeated rows.
df['InputStable'] = df['InputBus'] == df['InputBus'].shift(periods=1, fill_value=0) & df['InputBus'].shift(periods=2, fill_value=0)
This creates a new boolean column, which contains true/false based on whether the current value equals the previous value and the one before that.
I think I'm binary bitwise ANDing two integers here and then comparing that result, which is probably breaking a thousand rules, but it seems to be working just fine in practice.
This utilizes the shift() function in pandas.
I also used drop() and drop_duplicates() to get rid repeated rows.