I have a set of data which includes various cycles and data points to correspond with.
I want to create a function that will go through and identify the letter A next to the start of the data and the Letter B to the end of the data.
For the following dataset:
import pandas as pd
data = {'Cycle': [1, 1, 1, 1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3],
'Value': [0,19,18,14,65,0,0,0,0,0,0,1,18,12,65,0,0,0,0,0,0,19,18,14,65,54,32,0,0,0]}
df = pd.DataFrame(data)
I would like to have a result like the following, with the values that arent POI's being a "-" similar to the following:
import pandas as pd
data = {'Cycle': [1, 1, 1, 1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3],
'Value': [0,19,18,14,65,0,0,0,0,0,0,1,18,12,65,0,0,0,0,0,0,19,18,14,65,54,32,0,0,0],
'POI': [0,'A',0,0,'B',0,0,0,0,0,0,'A',0,0,'B',0,0,0,0,0,0,'A',0,0,0,0,'B',0,0,0]}
df = pd.DataFrame(data)
I have tried using something like this:
data['POI2'] = data.groupby('Cycle').apply(
lambda g: np.select([g['Value'] == g['Value'].max(),
g['Value'] == g['Value'].min()],
['A', 'B'], default='-')
).explode().set_axis(data.index, axis=0)
With no luck. Basically I need to parse through the points for each cycle that are Nan or 0 and then identify the start and stop with an A and B.