Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

groupby and assign number to each group pandas

group_vars = ['a']
df.merge( df.drop_duplicates( group_vars ).reset_index(), on=group_vars )

   a  b  index
0  1  1      0
1  1  1      0
2  1  2      0
3  2  1      1
4  2  1      1
5  2  2      1
 
PREVIOUS NEXT
Tagged: #groupby #assign #number #group #pandas
ADD COMMENT
Topic
Name
8+8 =