group by in pandas with a column with numbers code example
Example: 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')
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')