I have a pandas dataframe like this:
Name Product Amount
0 Bob Apple 1
1 Bob Banana 2
2 Jessica Orange 3
3 Jessica Banana 4
4 Jessica Tomato 3
5 Mary Banana 2
6 John Apple 3
7 John Grape 1
import pandas as pd
data = [('Bob','Apple',1), ('Bob','Banana',2), ('Jessica','Orange',3),
('Jessica','Banana',4),('Jessica','Tomato',3), ('Mary','Banana',2),
('John','Apple',3),('John','Grape',1)]
df = pd.DataFrame(data,columns=['Name','Product','Amount'])
What I have done so far:
l = []
count=0
for i in range(0,8):
row = df.iloc[i]
if row.Product not in l:
l.append(row.Product)
Now, l contains all the unique values in the Product column, but I need the total amount as well.
How can I find out for each product how many items were sold (for example, 4 units of Apple were sold)?