I am using the following code to groupby and count/sum etc.
groups = df[df['isTrade'] == 1].groupby('dateTime')
grouped = (groups.agg({'tradeBid': [np.sum,lambda x: (x > 0).sum()],}))
The output is giving me:
tradeBid tradeBid
sum <lambda>
79 46
7 6
4 4
20 6
How can I change the output's header ( so my end user will know what is this data?
You can provide names like this:
groups.agg({
'tradeBid': [
('sum', np.sum),
('other', lambda x: (x > 0).sum())
]
})
It used to be you could use a dict
instead of a list of 2-tuples, but that is now deprecated (probably because the ordering of the columns is then arbitrary).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With