I have a DataFrame
col1 col2 col3 col4 col5 col6 col7 0 Sem 01.2017 2 4 Noo RX 1 Kola 01.2017 3 4 Foo RX 2 Kety 02.2017 4 3 Roo RX 3 Pyti 01.2017 5 5 Kaa RX 4 Pyti 02.2017 3 1 Joo RX 5 Kola 03.2017 8 3 PPP RX 6 Café 01.2017 1 1 Cf RX 7 Kety 02.2017 2 1 T RX I did groupby() on two fields col2, col3 and found the amount on field col4:
df.groupby(['col2', 'col3'])['col4'].sum() Happened:
col2 col3 col4 Kola 01.2017 3 03.2017 8 Kety 02.2017 6 Pyti 01.2017 5 02.2017 3 Sem 01.2017 2 Café 01.2017 1 But to the same grouping I need to add the third column ['col5'].unique()
The final result should look like this:
col2 col3 col4 col5 Kola 01.2017 3 4 03.2017 8 3 Kety 02.2017 6 [3,1] Pyti 01.2017 5 5 02.2017 3 1 Sem 01.2017 2 4 Café 01.2017 1 1