0

So I am trying to find rows where data indicates casualty - in this case, the dataset identifies an alarm signal, which then results in an error signal in the dataset between 1 and 14 days later.

Is it possible to create a 'fault' column, whereby once an alarm signal is detected, the 'fault' column is set to True for up to the next 14 days? df.loc attempts work but will only change one row for the corresponding day, whereas I would like a solution that can edit the corresponding day and the remaining 13 days too! This way I can then check the date of the error signal against the range of dates of alarm signals, to determine if the fault actually occurred.

eg. pseudo data

time           vibration_value    fault?
2007-06-01     50                 False
2007-06-02     47                 False
2007-06-03     29                 False
2007-06-04     52                 False
2007-06-05     455                True
2007-06-06     672                True
2007-06-07     513                True
2007-06-08     532                True
2007-06-09     510                True
2007-06-10     498                True
2007-06-11     12                 False
2007-06-12     25                 False
2007-06-13     19                 False
2007-06-14     46                 False

I'm achieving this for the first fault result with the below code, but am unsure how to get this to edit the subsequent rows.

df.loc[df['vibration_value'] >= 250,  'Fault'] = True
3
  • Apologies, sorted now Commented Feb 22, 2017 at 14:19
  • The desired output is that the 'Fault' column remains True for the extra few days, so that I can cross-reference against the days when data doesn't quite align correctly Commented Feb 22, 2017 at 14:28
  • What if df['vibration_value'] >= 520 and need last 3 days? Commented Feb 22, 2017 at 14:56

1 Answer 1

1

As per my understanding of your question, this should work.

df.ix[df['vibration_value'] >= 250,  'Fault'] = True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.