(upbeat music)
- [Instructor] Let's review my solution to this challenge.
So I use the read Excel function
to read the data into a data frame
to hold all the sales information,
and that shouldn't be too hard.
That's pretty easy.
Then I defined a list that's going to hold the strings
for the column headers in the summary sheet,
and we'll use that later.
All right, then we saw earlier in the chapter
how to use the unique function to get the unique values
for a particular column in a data frame.
And so I'm going to use that here
to loop over each product name that appears
in that particular column.
So then I use the LOC function,
which again we saw earlier in the chapter,
to select the gross sales
and profit columns for each product,
and then calculate the sum of those rows
where the product name
matches the current prod name variable of my loop.
And then I add a new row to my summary data list
for that calculation.
So when this loop completes,
I create a new data frame with my summary data array
that has now been filled in,
and I specify that the columns are going
to be the headers I specified up here, right?
And then I use the Excel writer object
to append a new worksheet to the existing file.
And again, we saw how to do this earlier in the chapter.
So I would suggest maybe taking some time here
to try out some of your own experiments.
So for example, how would you expand on this challenge
to include the country data from column B?