0

I am trying to find the points in a dataframe where the data hits a max value, holds it for a time, then drops down again (See image below).

enter image description here

I am attempting to find the index's where the value first hits the max and where it first leaves it. I've attempted it in the following way.

ent = data.loc[data['ESC_Command'] == 1600 and data['ESC_Command'].shift() < 1600]
lve = data.loc[data['ESC_Command'] == 1600 and data['ESC_Command'].shift(-1) < 1600]

But when I run this I get the following error.

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

If I run either the 'equals to 1600' or the '< 1600' with the shift I get the expected boolean list but adding a logical statement gets me that error. Don't suppose anyone can shed some light onto what I'm missing?

Thanks in advance!

BikeControl
  • 179
  • 2
  • 9

1 Answers1

1

You will want to use the bitwise operator (&) to combine your masks ((data['ESC_Command'] == 1600) & (data['ESC_Command'].shift() < 1600)).

and is the logical operator and is unable to compare series, hence the ValueError.


Also, you can use data['ESC_Command'].max() to dynamically find the maximum value in the column.

  • Ah, thanks! I was guessing I was just doing something dumb like that! I didn't think I could use the .max() operator as the series hits that max value multiple times and I needed to identify each one. – BikeControl Nov 11 '18 at 13:49