Skip to content
Advertisement

How am I able to replace duplicates in a dataframe column in python?

say my column is something like this:

JavaScript

I would like to drop the duplicate elements in the column and replace them with NAN or 0 so it would end up with something like:

JavaScript

I am completely unsure of the logic I can use to do this, I think I would forward fill up until the next change in signal with NAN values somehow?

Advertisement

Answer

Try mask with shift:

JavaScript

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