How do I calculate the number of consecutive columns with zero values from the right until the first non zero element occurs

Viewed 237

Suppose I have the following dataframe:

   C1 C2 C3 C4  
0  1  2  3  0  
1  4  0  0  0  
2  0  0  0  3  
3  0  3  0  0 

Then I want to add another column such that it will display the number of zero valued column that occur contiguously from the right. The new column would be:

  Cnew  
0 1  
1 3  
2 0  
3 2  
3 Answers
Related