From the course: Advanced Hands-On Python: Working with Excel and Spreadsheet Data

Unlock the full course today

Join today to access over 24,600 courses taught by industry experts.

Solution: Excel insight

Solution: Excel insight

(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…

Contents