Pandas select first row for each value group I have a datetime-indexed Pandas dataframe such as:
longitude  latitude  group_1
timestamp
2019-01-04 08:25:10    47.4900  -18.7983      1.0
2019-01-04 08:25:20    47.4983  -18.8000      1.0
2019-01-04 08:25:28    47.5050  -18.8000      1.0
2019-01-04 08:25:36    47.5133  -18.8000      1.0
2019-01-04 08:25:44    47.5200  -18.7967      1.0
2019-01-04 08:25:52    47.5250  -18.7933      1.0
2019-01-04 08:26:05    47.5367  -18.7867      1.0
2019-01-04 08:26:21    47.5500  -18.7767      1.0
2019-01-04 08:26:34    47.5600  -18.7683      1.0
2019-01-04 08:26:42    47.5683  -18.7633      1.0
2019-01-04 08:27:05    47.5900  -18.7483      1.0
2019-01-04 08:27:53    47.6350  -18.7150      1.0
2019-01-04 08:28:40    47.6817  -18.6783      1.0
2019-01-04 08:33:44    48.0700  -18.3933      NaN
2019-01-04 08:54:05    49.6333  -17.2233      NaN
2019-01-04 08:55:43    49.7233  -17.1667      NaN
2019-01-04 08:57:43    49.8117  -17.1450      NaN
2019-01-04 09:59:44    49.8150  -17.0900      NaN
2019-01-04 10:00:02    49.8133  -17.0767      1.0
2019-01-04 10:00:09    49.8117  -17.0717      1.0
2019-01-04 10:00:31    49.8050  -17.0567      1.0
2019-01-04 10:02:49    49.7483  -16.9183      1.0
2019-01-04 10:39:12    48.5383  -13.6500      1.0
2019-01-04 10:45:31    48.3683  -13.3033      NaN
2019-01-04 10:46:47    48.3317  -13.2933      NaN
2019-01-04 10:47:11    48.3217  -13.3033      NaN
2019-01-04 11:40:01    48.3567  -13.3483      1.0
2019-01-04 11:40:41    48.3500  -13.3917      1.0
2019-01-04 11:41:23    48.3433  -13.4383      1.0
2019-01-04 11:42:07    48.3350  -13.4867      1.0

How can I select the rows corresponding to the first value in each group of 1.0 in group_1? Using the example data above, desired output is:
longitude  latitude  group_1
timestamp
2019-01-04 08:25:10    47.4900  -18.7983      1.0
2019-01-04 10:00:02    49.8133  -17.0767      1.0
2019-01-04 11:40:01    48.3567  -13.3483      1.0


Create a mask to separate the islands of NaN values and use groupby + idxmax
u = df['group_1']    
m = u.isnull() & u.shift().notnull()
ii = u.groupby(m.cumsum()).idxmax()

df.loc[ii]


longitude  latitude  group_1
timestamp
2019-01-04 08:25:10    47.4900  -18.7983      1.0
2019-01-04 10:00:02    49.8133  -17.0767      1.0
2019-01-04 11:40:01    48.3567  -13.3483      1.0


You can try (works with any form of 1 blocks):
s = df['group_1'].ne(1)
blocks = s.cumsum()
df[~s].groupby(blocks[~s], group_keys=False).head(1)

Or without groupby (works when 1 blocks interleave with the nans):
df[df.group_1.shift().fillna(0).lt(df.group_1)]

Output:
longitude  latitude  group_1
timestamp
2019-01-04 08:25:10    47.4900  -18.7983      1.0
2019-01-04 10:00:02    49.8133  -17.0767      1.0
2019-01-04 11:40:01    48.3567  -13.3483      1.0