I'm trying to identify the best way to make a simple pivot on my data:
import pandas
dfn = pandas.DataFrame({
"A" : [ 'aaa', 'bbb', 'aaa', 'bbb' ],
"B" : [ 1, 10, 2, 30 ],
"C" : [ 2, 0, 3, 20 ] })
The output I would like to have is a dataframe, grouped by A
, that sum and count values of B
and C
, and names have to be exactly (Sum_B
, Sum_C
, Count
), as following:
A Sum_B Sum_C Count
aaa 3 5 2
bbb 50 20 2
What is the fastest way to do this?