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

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Solution: Split a workbook

Solution: Split a workbook

(upbeat music) - [Instructor] Okay, let's review my code. So here's my solution file. So for this challenge, we had to take the inventory CSV file and transform it into an Excel workbook with separate worksheets for each of the categories of the items in the file. Well, we already know how to read a CSV file because we saw that earlier in the course. So the first part of my code does exactly that. I create two variables. One of them is a default dict that maps a string to a list to hold each of the category names. And the other is going to hold the first header row so I can use it over and over again. So this is my function to read the CSV data. So it opens the file, reads the first row, and then stores that value, the first row into my global variable, which is this headers array right here. And again, I do this so that I can write the headers to each worksheet later. And then, of course, I read in each row, and I use the value at index one, the column index one, which remember is…

Contents