I have 2 columns in my dataframe: x and y. x is continually repeating between 1-4 and I need to find out some statistics about the sections where x=2, e.g. mid-point and average etc. I have created a third column using .shift(-1):
df['x_shift']=df['x'].shift(-1)
x y x_shift
1 25 1
1 25 1
1 25 2
2 25 2
2 45 2
2 90 3
3 90 3
3 90 3
3 90 4
4 60 4
4 40 1
1 25 1
1 25 1
1 25 2
2 43 2
2 66 2
2 77 2
2 90 3
3 90
Using this, I have identified the points where x changes from 1 to 2 and from 2 to 3 to mark the start and end of where I need the data:
start point = df.ix[(df['x']==2) & (df['x_shift']==2)]
final point = df.ix[df['x']==2) & (df['x_shift']==3)]
I have tried to create groups to generate statistics, but I wasn't sure how to include the above within groupby:
grouped = df.groupby( )
The intention is to use grouped.describe() to generate statistics, which I am hoping that I will be able to also extract and plot?