Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

PREVIOUS NEXT
Code Example
Python :: for j in range python 
Python :: how to take input a matrix using map in python 
Python :: py draw matrix of black square and white circle 
Python :: python strong type 
Python :: how to go from a url with a zip file to a csv 
Python :: what is quit block in python 
Python :: remove uppercase letters python 
Python :: give access to normal user like super user 
Python :: Access value 
Python :: python requests-session for websites wihout login 
Python :: writer.append_data(image) means 
Python :: hide model field form 
Python :: if elif ladder in one line in python 
Python :: how to pass on all the arguments to internal function in python 
Python :: Print 10 most important features ascending 
Python :: Python Tkinter Scrollbar Widget Syntax 
Python :: symmetric_difference_update() Function of sets in python 
Python :: python datetime toordinal 
Python :: python keyword search engine 
Python :: gensim loop keyed vector 
Python :: numpy.floor_divide() in Python 
Python :: Call a function after every x seconds 
Python :: slice all elements from list 
Python :: flask in colab ngrok error 
Python :: python pattern glob extension searching 
Python :: how to reorder columns in pandas 
Python :: get random bright hex color python 
Python :: python array_combine 
Python :: File "demo_indentation_test.py", line 2 print("Five is greater than two!") ^ IndentationError: expected an indented block 
Python :: truc python 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =