Pandas Group By
data.groupby('amount', as_index=False).agg({"duration": "sum"})
Tirbo06
data.groupby('amount', as_index=False).agg({"duration": "sum"})
pd.DataFrame( {'a':['A','A','B','B','B','C'], 'b':[1,2,5,5,4,6]})
df.groupby('a')['b'].apply(list)
Out:
a
A [1, 2]
B [5, 5, 4]
C [6]
Name: b, dtype: object
In [21]: g1.add_suffix('_Count').reset_index()
Out[21]:
Name City City_Count Name_Count
0 Alice Seattle 1 1
1 Bob Seattle 2 2
2 Mallory Portland 2 2
3 Mallory Seattle 1 1