I have a data frame with a lot of cycles and I am trying to find the local max and min to identify peaks.
I have currently done this:
Data3['POI'] = Data3.groupby('Cycle#').apply(
lambda g: np.select([g['Value'] == g['Value'].max(),
g['Diff2'] == g['Diff2'].min()],
['A', 'B'], default='-')
).explode().set_axis(Data3.index, axis=0)
I identified when a cycle starts and stops and identified it as Cycle#, where I then search for the max value to label it as Point A and then the min of the 2nd derivative to try and find B. However I am getting this result where you can see my A (start of peak) and B are off (end of peak):

I am now trying to use local max/mins to attempt to find points A and B which should look like this (with A being the start of the peak and B being the end of the peak):

I attempted to use this to solve this:
Data3['POI'] = Data3.groupby('Cycle#').apply(
lambda g: np.select([g['Value'] == g.Value[(g.Value.shift(10) < g.Value) & (g.Value.shift(-10) < g.Value)],
g['Diff2'] == g['Diff2'].min()],
['A', 'B'], default='-')
).explode().set_axis(Data3.index, axis=0)
But I am getting this error: ValueError: Can only compare identically-labeled Series objects
I am looking for a better way to solve this problem to identify these two key points per cycle.