Reputation: 21
I have a data frame read from a csv log file. One of the columns that I am studying is Fan Speed. There were several fan speed step changes during the log. I want to automatically find the last index of each Fan Speed Change Step for the entire log. How should I approach this ? I am new to python. Some guidance are appreciated !
ffl3883
Upvotes: 1
Views: 249
Reputation: 4673
You can get a series of changes in Series values using Series.diff()
. Then, you could compare the absolute value of those changes to some tolerance that you choose.
STEP_CHANGE_TOLERANCE = 2500
idx = df[df["SYS_FAN_0_0"].diff().abs() > STEP_CHANGE_TOLERANCE].index
The code above will give the first (I think) index value of each new speed. If you want the last index of each region, you could try:
idx_fwd = df[df["SYS_FAN_0_0"].diff(-1).abs() > STEP_CHANGE_TOLERANCE].index
Upvotes: 1