Chain another mask created by Series.duplicated
with keep=False
by &
for bitwise AND
and filter in boolean indexing
:
ss = df.Stock.ne(df.Stock.shift())
ss1 = ss.cumsum().duplicated(keep=False)
df = df[ss & ss1]
CLICK HERE to find out more related problems solutions.