I have a dataset similar to the dataset shown below:
Name Country Sales
Alice USA 1000
Bob Canada 500
Charlie UK 2000
Bob Canada 700
Alice USA 200
David USA 1200
Charlie UK 600
Alice USA 2000
And I am trying to find the total sales made by each person based on which country they are from, in other words, I want to subset or group the data based on the country to which they belong and then group them on the basis of their names and then find the total sales for each person. Please provide me with different methods with example codes for doing this task. You can use the following dataframe code to get started:
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'Bob', 'Alice', 'David', 'Charlie', 'Alice'],
'Country': ['USA', 'Canada', 'UK', 'Canada', 'USA', 'USA', 'UK', 'USA'],
'Sales': [1000, 500, 2000, 700, 200, 1200, 600, 2000]
}
df = pd.DataFrame(data)