Previously, you learn how to create one single PDF of documents via Python.
In this video, you learn how to create multiple PDF documents with dots of fetched from an Excel file.
The file we'll be using is this one in here.
You can find this untouched in this lecture as a resource.
So let me quickly explain what these dots are.
So we have one two three four five six columns and each row.
Represent one type of animal, for example, the first one is in both Malayan tigers.
So you have the kingdom that's a million tiger belongs to the film.
So biological classification of animals.
Then you have the class, the older and the sub order.
So each animal has their own classifications.
Three animals we have here now.
What we will do is we will generate a PDF document for each of these rows.
The documents will look like this.
So we had the American leg bear, the Bumblebee and the Malayan tiger.
The American Blackbear PGA Tour will look like this.
So that's the name of the animal.
And then we have the -.so here.
So the kingdom is animalia.
The film is called -.So, etc..
For the Bumble Bee, we also have these dots on, so these dots are obviously come from the rows of
this Excel file.
And of course, the PDFs will be generated in one singular run over the script.
So that's build on this program of the Leave this PDFs, and I'll go to the SHALL section and just see
our.
Asterisk that PDF executes.
So now I'll start from scratch.
First of all, we want to load the dots into Python.
We do this using pandas.
So Dev is equal to pandas.
That's right.
Excel is the methods this gets as input data that excel, this ex of a path to that excel file.
No, for this the work you needs.
To have the FPGA package installed, the panda's package and also you need to install.
In Rebel, I have to instill this with tape.
So this is PIP install open p y excel.
So that's a dependency for reading excel files for the pandas package.
So you have to run that then.
The other ones, you can install them from the graphical installer here sort of feeds on panels and
you're good to go.
So we load the data and let's free the mouse just to see if we read them correctly.
Yep, so that's our data frame.
There is an error here, but I think that is some bugs related to a report currently because I don't
see any error in our codes here, so let's ignore that, Sarah.
Of this is that these are free.
So that's of the same doctor as in the Excel file, we see that we have zero one two.
So it's three euros and this first row here, which you saw in here, that is the heads are so from
automatically recognize it's as a header and then it starts with a visceral second third.
And each column.
So now what we need to do is iterate over those dots.
We do that's using four index rule and ZF rules, so that's a standard way to iterate over the dots
on basically what we get is.
Let me show you what index is first.
So index is that zero one two?
So we're printing out the index number for each group and the rules themselves are.
So let me comment that out and let's bring the rule.
So this is what we get for Rose.
That's the first rule from there to here.
That's the second rule.
That's the third rail.
So each row has these pairs of the name of the column and the value of the column, so that's for the
bumblebee.
There's a name of the animal, that's the kingdom of the animal.
The fill them of the animal and so on.
So that's for the third row only.
That's for the second row, and that's for the first rule.
So we need to use these rules now, somehow we're going to need to extract, for example, the name,
which is.
That's and that's and that's and you can do that by entering year square brackets and includes name.
So that's in the name.
There, if you run that, you're going to get some alone Tiger American Black Bear and some bumble bee
if you enter Kingdom.
So the name of the second column, we just use the name now we use Kingdom.
Let's see.
Run and three gets Animalia, so that's the same kingdom for all the animals here, so let's make use
of that now.
Instead of bringing it out, let's insert these dots on into our PDF into a new PDA document.
For that, we need to import from F PDF import.
EPRDF then.
We need to create a new instance for that.
But one instance correspond to one PDA file.
And we want three PDF files in this case.
We have three rows, three animals, three PDF files.
Therefore, for each iteration we want to insert here.
We want to create that instance.
So PDF?
Orientation to pee, so portrait mode we cover, that's in the previous lecture, so you need to take
that lecture if you didn't do so already.
The units over the phones.
And the other elements would be in petty points and the formats would be an eye for.
Then we'll add a page to the PDF.
It's an empty page from now.
So then next, let's add the first.
Item.
Contents in the PDF.
So we said that we want the ads in the PDF page, we want to add content from top to bottom.
So the first thing I want to add is some sort of a title.
And I do have the codes from the previous lecture to add to the title, which works like this I'm going
to paste this year.
So that is the codes.
We said the font times.
It's a big fonts, 24 points in size and then we add the cell.
So the text was static aesthetics, three Malayan Tiger, but we want to make this dynamic now, so
instead of Malayan Tiger, we will add here room.
Name no.
If I just call Alt Foods right now.
And as the name, I'll use an ashtray.
So to make it dynamic, I'll do again rule.
Name.
And outside the curly brackets, so that will be replaced by name or by the name of the animal, which
is, for example, American Black Bear.
And then at the end, all at that PDAF and run this.
And there we go, we get to three --.
That's a first title, the second title Bumblebee and the third title.
Now let's add those dots on down here.
Again, I have a code from the previous lecture cockpits on my clipboard, so I'm going to add it's
between this cell and the outputs methods.
So somewhere here.
Indented properly to be on the for loop.
So what we have got here is we add the text kingdom, and next to that we adds a type of kingdom which
is on the model year.
Now this is the label, so that's the name of the column.
So what we will do is we will just leave it Kingdom, so that's the next column.
Event change this.
To borrow.
King.
That's the name of the column, so that's just a label.
We will insert that as simple text.
But this will get the value from the current row.
So of iteration goes like you, the first iteration we we are working on the first rule, which is.
Four million, Tiger.
And so we get the name for the Malayan tiger here, and then we get the kingdom for the Malayan tiger
in here and everything is written in this --.
So the they run this.
And check again.
So American Black Bear Kingdom, Animalia, all the animals are obviously the same kingdom, so everything
is working fine.
We can keep adding rows like that's here.
So I'm replicating that.
And then the next column would be Finland.
And then here we see.
Fill them.
So this will work if we keep doing that for all the columns.
But since we're working on automation, it doesn't make much sense to keep repeating ourselves here
with the codes.
So I think we can do better and.
Automates this as well.
So what I'll do is.
Just after we aired the title in here.
So that's for the title of a sponsor.
After that, I will insert a new full loop.
Let me see how we can do that.
So just off the title, you see wrong name here?
I'll say full column in RDF columns.
So I'm iterating over the column names because of that's columns is of this series, which gives us
all the column names.
But if we do four column in.
Do you have those columns?
And we print the column here.
We get access to all those columns.
These are all strings.
No.
And if we do.
Full column in columns from the second column up to the loss column.
Print column that will print out all the columns, but the first one you see name is here, but it's
not here because we exclude it name.
So when you see that?
You are slicing that, least by by taking only those items, not the item with index one.
So let's make use of that for the loop in here.
See, uh, one to the end and then.
Instead of putting these texts in here, we make it dynamic, we see column.
So, Kingdom, and if you want, you can make it a type of case, so it will be something like Kingdom,
the title and key will be capitalized, so it's title.
And if you want to keep the the column here, then you want to use f string.
So f they're like that.
Put that in curly brackets, so that's a dynamic part of a string.
And then we have the static force.
It's just a column.
After Kingdom and then we go here, so this no kingdom is again replaced by column because column in
the first iteration, a sequel to Kingdom, and that allows us to delete all these other ones.
Right.
We have this other line here, which means we have to indent this to make it synthetically correct.
So that's indented under the first full loop and that's indented under the second full loop.
Of course, we didn't include this part in the second for Loop because we have to create one PDF documents
for each role, but then under the iteration of each arrow, we want to do something repetitive in each
document, and the generation of the title is not repetitive.
But this code was repetitive, so we had to include it in a full look.
Um, let's run this.
And let's check now looks good.
Kingdom films class orders of honor.
That's for the American Black Bear.
Let's see for Bumblebee.
Yeah.
We have other does all the classes in sector, obviously.
And that's how we can create multiple PDAF reports via Python.
If you're working with these results are, of course, you can just change these to release GSV and
then provides you the link to your see as file.
The path to your see is a file, and that should do it.
So thank you for following, and I'll talk to you later.