0

Hay I have this series:

3274
3274
2374
2374
2375
2374
2374
3275

Now I want to Marge all the subsequent rows and take the first row(that start the sequence)

For the example above I want the outcome be this:

3274
2374
2375
2374
2375
2374
3275

There is a sample way to that instade of iterate the all series and search for sequences?

Thanks

1 Answers1

0

Use boolean indexing wit compare shifted values by Series.shift with not equal by Series.ne:

df = df[df['col'].ne(df['col'].shift())]
print (df)

    col
0  3274
2  2374
4  2375
5  2374
7  3275
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252