Question: ```
df = pd.DataFrame({'col1':['A','A','B'], 'col2':[1,2,1]})

```

I'd like to group the results into tuples inside a list:

```
[ ('A', [1,2]), ('B',[1]) ]

```

I thought `list(df.groupby(by='col1')['col2'])` would be sufficient but the second element of the tuple is a Series.

`df.groupby(by='col1')['col2'].apply(lambda x: x.values.tolist())` also does not quite do what I intend.

Answer: 
You can use [`GroupBy.agg`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.agg.html) to list, then use [`df.to_records`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_records.html) and convert it to list.

```
df.groupby('col1').agg(list).to_records().tolist()
# [('A', [1, 2]), ('B', [1])]

```
You could add the `agg` function with `list` and then `zip` the final result :

```
result = df.groupby(by="col1")["col2"].agg(list)
list(zip(result.index, result))
[('A', [1, 2]), ('B', [1])]

```