I have the following df, which I would like to group by 'Name' so there is an 'A' and 'B' count column and a 'total sales' sum column:
eg turn this:
data = {'A or B' : ['A','A','B','B','A','B'],
'Name' : ['Ben','Ben','Ben','Sam','Sam','Sam'],
'Sales ($)' : [10,5,2,5,6,7]
}
df=pd.DataFrame(data, columns = ['A or B','Name','Sales ($)'])
so it looks like this:
grouped_data = {'A' : [2,1],
'B' : [1,2],
'Name' : ['Ben','Sam'],
'Total Sales ($)' : [17,18]
}
df=pd.DataFrame(grouped_data, columns = ['A','B','Name','Total Sales ($)'])