Skip to content
Advertisement

skip na while removing consecutive same numbers in a column in python

I have to remove the consecutive same number from the column in a dataframe. I am able to remove the number one time, but when I try to do it for the second time the loop does not work as there is one na value in between.

dataframe is

JavaScript

I dont know why the last line of code i.e. elif condition is not working.

Advertisement

Answer

If you were willing to abandon the loop idea you could:

JavaScript

Result

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement