Move from Excel to Python with Pandas Transcripts
Chapter: Data I/O (input and output)
Lecture: Demo: Complex Excel saves
0:00 we're gonna do is we're gonna create some additional cells to do the formatting for us
0:05 So what this code does is it uses the writer object that we created here
0:17 toe pull out the workbook and then from the workbook were accessing the sales summary
0:23 worksheet. And the first thing we need to do is add a number format, and in this case, you use a dictionary, What you want to call it,
0:30 and I want to call this numb format. I'm setting a comma so that the numbers are formatted as decimals with commas.
0:38 And this uses thesis, aim formatting structure you would use within excel. And then let's add another. So and now we need to apply the formatting.
0:47 So on our worksheet in this example now we are saying for each of the columns in the sales summary columns a through B,
1:05 we want to be with 18 see, we want with a team. But we also want to apply the number format and columns ether G. We want to be a little bit narrower,
1:16 but also have the number format. Now, if we want to get worksheet number two so we've done a similar set
1:31 of instructions for the product. Summary tab primarily defined products Summary up here Now we're
1:36 saying a three D need to be numeric columns and the in the format we defined and need to have a width of 16.
1:44 So let's rerun all of this and see what our new file looks like. Now this looks a lot nicer. So I just open up the file and did not do any formatting.
1:57 The columns are wide so you can see all your data. There are decimal points and commas, and we have two decimal points for all of our numbers.
2:05 And you can see there does it on the second page as well. And the reason I wanted to go through this is as you start to output Excel
2:13 This is probably the format you're gonna share with others. So it's really important that you have this capability toe format it in a way that