Answers for "pandas increment value on condition"

0

pandas increment value on condition

In [47]: df['ans'] = (df['ix'] != df['ix'].shift(1)).cumsum()

In [48]: df
Out[48]: 
   index  ix  ans
0      1  pa    1
1      2  pa    1
2      3  pa    1
3      4  pe    2
4      5  fc    3
5      6  pb    4
6      7  pb    4
7      8  df    5
Posted by: Guest on August-05-2021

Code answers related to "pandas increment value on condition"

Python Answers by Framework

Browse Popular Code Answers by Language