Have a pandas dataframe,need to find last value lower than certain value in the column within group.
dataframe is as following:
region year month signal
A 2010 2 20
A 2010 3 32
A 2010 4 24
A 2010 6 50
.......
A 2011 1 20
.......
B 2010 2 100
B 2010 3 20
.......
Now I need add one column of flag to label the last value lower than 25 in the first half year for each ["region","year"] combination. So for example for region A in the first half year of 2010, April signal value will be labeled as 1. Any suggestion for this? Thanks.