Here's how I would think to do it.
import pandas as pd
df = pd.DataFrame({0: {0: 1, 1: 0, 2: 0, 3: 1, 4: 0, 5: 1},
1: {0: 0, 1: 0, 2: 1, 3: 0, 4: 0, 5: 0},
2: {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
3: {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
4: {0: 1, 1: 0, 2: 1, 3: 1, 4: 0, 5: 1}})
groups = df.groupby(df.columns.tolist())
df.loc[:, 'group_num'] = None
for num, group in enumerate(groups):
df.loc[group[1].index, 'group_num'] = num
Yields...
0 1 2 3 4 group_num
0 1 0 0 0 1 2
1 0 0 0 0 0 0
2 0 1 0 0 1 1
3 1 0 0 0 1 2
4 0 0 0 0 0 0
5 1 0 0 0 1 2
Why group[1] on the last line?
Because you're iterating through a tuple of the form (group_name, group_table). group[1] accesses the actual grouped DataFrame.