I have a data frame that contains several identifiers. I want to create one new 'group identifier' for every unique combination of the identifiers - Later on, I want to run regressions using `statsmodels`. That is, say I have

```
  id1 id2 id3 
    A   1 100
    A   1 101
    B   1 100
    B   1 100

```

I want to get

```
  id1 id2 id3 groupid 
    A   1 100       0
    A   1 101       1
    B   1 100       2
    B   1 100       2

```

with `id1`, `id2`, `id3` as the set of identifiers. I know that I can get `unique()` to get the unique groups, but how would I efficiently code the rows into which of the unique groups they belong?

Adjusted @Bernie's answer to accommodate for potential 'NaN's:

```
# get a DataFrame with just the unique "keys"
df2 = df.replace(np.NaN, -1)
g = df2.groupby([u'id1',u'id2',u'id3'])
gdf = pd.DataFrame(g.groups.keys(),columns=df.columns)
gdf = gdf.replace(-1, np.NaN)
# an idea is to re-use the index as the 'group_id'
# the next three commands support that 
gdf.sort([u'id1',u'id2',u'id3'],inplace=True)
gdf.reset_index(drop=True,inplace=True)
gdf['group_id'] = gdf.index

# merge on the three id columns
mdf = df.merge(gdf,how='inner',on=df.columns.tolist())

```