IIU C - для эквивалентного вопроса df.loc[]
вы можете просто сделать:
df=df.set_index('a')\
.loc[df.groupby('a').b.agg(np.ptp).gt(3)]\
.reset_index()
В качестве альтернативы (решение внутреннего соединения):
selector=df.groupby('a').b.agg(np.ptp).gt(3)
selector=selector.loc[selector]
df=df.merge(selector, on='a', suffixes=["", "_dropme"])
df=df.loc[:, filter(lambda col: "_dropme" not in col, df.columns)]
Выходы:
a b
0 10 1
1 10 5
Ps +1 @ rafael c - за .ptp
вещь