Finding first repeated consecutive entries in pandas dataframe

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.

Leave a Comment

Your email address will not be published.

Scroll to Top