Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas sequential numbering within group

tmp = pd.DataFrame({'a':[1,1,2,2,3,1,2,3,1,3,1,2]})
tmp['sequential'] = tmp.groupby('a').cumcount()
tmp.sort_values('a')
 
PREVIOUS NEXT
Tagged: #pandas #sequential #numbering #group
ADD COMMENT
Topic
Name
3+1 =