Skip to content
Advertisement

Counting consecutive occurrences of a specific value in PySpark

I have a column named info defined as well:

JavaScript

I would like to count the consecutive occurrences of 1s and insert 0 otherwise. The final column would be:

JavaScript

I tried using the following function, but it didn’t work.

JavaScript

Advertisement

Answer

From Adding a column counting cumulative pervious repeating values, credits to @blackbishop

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