1
00:00:02,140 --> 00:00:07,000
Previously, you learn how to create one single PDF of documents via Python.

2
00:00:07,240 --> 00:00:16,030
In this video, you learn how to create multiple PDF documents with dots of fetched from an Excel file.

3
00:00:16,329 --> 00:00:19,000
The file we'll be using is this one in here.

4
00:00:19,450 --> 00:00:23,620
You can find this untouched in this lecture as a resource.

5
00:00:24,550 --> 00:00:27,430
So let me quickly explain what these dots are.

6
00:00:27,910 --> 00:00:33,670
So we have one two three four five six columns and each row.

7
00:00:34,730 --> 00:00:40,580
Represent one type of animal, for example, the first one is in both Malayan tigers.

8
00:00:41,810 --> 00:00:47,270
So you have the kingdom that's a million tiger belongs to the film.

9
00:00:47,270 --> 00:00:51,560
So biological classification of animals.

10
00:00:52,220 --> 00:00:54,650
Then you have the class, the older and the sub order.

11
00:00:54,860 --> 00:00:58,260
So each animal has their own classifications.

12
00:00:59,060 --> 00:01:01,540
Three animals we have here now.

13
00:01:01,760 --> 00:01:08,930
What we will do is we will generate a PDF document for each of these rows.

14
00:01:09,740 --> 00:01:11,840
The documents will look like this.

15
00:01:12,200 --> 00:01:17,930
So we had the American leg bear, the Bumblebee and the Malayan tiger.

16
00:01:18,260 --> 00:01:20,840
The American Blackbear PGA Tour will look like this.

17
00:01:21,020 --> 00:01:23,120
So that's the name of the animal.

18
00:01:23,990 --> 00:01:25,280
And then we have the -.so here.

19
00:01:25,640 --> 00:01:27,330
So the kingdom is animalia.

20
00:01:27,870 --> 00:01:29,960
The film is called -.So, etc..

21
00:01:31,260 --> 00:01:39,560
For the Bumble Bee, we also have these dots on, so these dots are obviously come from the rows of

22
00:01:39,570 --> 00:01:40,800
this Excel file.

23
00:01:41,550 --> 00:01:49,200
And of course, the PDFs will be generated in one singular run over the script.

24
00:01:49,590 --> 00:01:57,960
So that's build on this program of the Leave this PDFs, and I'll go to the SHALL section and just see

25
00:01:57,960 --> 00:01:58,320
our.

26
00:02:00,240 --> 00:02:03,480
Asterisk that PDF executes.

27
00:02:05,900 --> 00:02:07,880
So now I'll start from scratch.

28
00:02:09,350 --> 00:02:12,280
First of all, we want to load the dots into Python.

29
00:02:12,680 --> 00:02:14,210
We do this using pandas.

30
00:02:15,560 --> 00:02:17,360
So Dev is equal to pandas.

31
00:02:17,390 --> 00:02:18,260
That's right.

32
00:02:19,340 --> 00:02:28,580
Excel is the methods this gets as input data that excel, this ex of a path to that excel file.

33
00:02:29,690 --> 00:02:31,730
No, for this the work you needs.

34
00:02:33,210 --> 00:02:40,500
To have the FPGA package installed, the panda's package and also you need to install.

35
00:02:44,330 --> 00:02:46,670
In Rebel, I have to instill this with tape.

36
00:02:47,960 --> 00:02:53,660
So this is PIP install open p y excel.

37
00:02:54,290 --> 00:02:59,630
So that's a dependency for reading excel files for the pandas package.

38
00:02:59,900 --> 00:03:02,690
So you have to run that then.

39
00:03:05,180 --> 00:03:11,360
The other ones, you can install them from the graphical installer here sort of feeds on panels and

40
00:03:11,360 --> 00:03:12,080
you're good to go.

41
00:03:13,070 --> 00:03:19,340
So we load the data and let's free the mouse just to see if we read them correctly.

42
00:03:20,860 --> 00:03:23,360
Yep, so that's our data frame.

43
00:03:25,840 --> 00:03:33,430
There is an error here, but I think that is some bugs related to a report currently because I don't

44
00:03:33,430 --> 00:03:37,180
see any error in our codes here, so let's ignore that, Sarah.

45
00:03:38,430 --> 00:03:39,660
Of this is that these are free.

46
00:03:43,550 --> 00:03:50,760
So that's of the same doctor as in the Excel file, we see that we have zero one two.

47
00:03:50,780 --> 00:03:59,750
So it's three euros and this first row here, which you saw in here, that is the heads are so from

48
00:03:59,900 --> 00:04:06,140
automatically recognize it's as a header and then it starts with a visceral second third.

49
00:04:07,620 --> 00:04:08,490
And each column.

50
00:04:09,090 --> 00:04:14,460
So now what we need to do is iterate over those dots.

51
00:04:16,769 --> 00:04:25,560
We do that's using four index rule and ZF rules, so that's a standard way to iterate over the dots

52
00:04:25,580 --> 00:04:28,200
on basically what we get is.

53
00:04:29,400 --> 00:04:31,860
Let me show you what index is first.

54
00:04:33,090 --> 00:04:39,030
So index is that zero one two?

55
00:04:39,270 --> 00:04:46,410
So we're printing out the index number for each group and the rules themselves are.

56
00:04:46,950 --> 00:04:50,040
So let me comment that out and let's bring the rule.

57
00:04:54,360 --> 00:04:56,220
So this is what we get for Rose.

58
00:04:56,790 --> 00:05:00,990
That's the first rule from there to here.

59
00:05:01,440 --> 00:05:02,940
That's the second rule.

60
00:05:04,470 --> 00:05:05,880
That's the third rail.

61
00:05:06,090 --> 00:05:14,640
So each row has these pairs of the name of the column and the value of the column, so that's for the

62
00:05:14,640 --> 00:05:15,240
bumblebee.

63
00:05:15,430 --> 00:05:18,870
There's a name of the animal, that's the kingdom of the animal.

64
00:05:19,710 --> 00:05:21,720
The fill them of the animal and so on.

65
00:05:21,990 --> 00:05:24,450
So that's for the third row only.

66
00:05:26,920 --> 00:05:30,100
That's for the second row, and that's for the first rule.

67
00:05:30,520 --> 00:05:38,410
So we need to use these rules now, somehow we're going to need to extract, for example, the name,

68
00:05:38,410 --> 00:05:39,070
which is.

69
00:05:39,250 --> 00:05:49,180
That's and that's and that's and you can do that by entering year square brackets and includes name.

70
00:05:50,080 --> 00:05:51,430
So that's in the name.

71
00:05:52,910 --> 00:05:59,600
There, if you run that, you're going to get some alone Tiger American Black Bear and some bumble bee

72
00:05:59,810 --> 00:06:01,100
if you enter Kingdom.

73
00:06:02,180 --> 00:06:08,000
So the name of the second column, we just use the name now we use Kingdom.

74
00:06:09,090 --> 00:06:09,920
Let's see.

75
00:06:13,820 --> 00:06:21,200
Run and three gets Animalia, so that's the same kingdom for all the animals here, so let's make use

76
00:06:21,200 --> 00:06:21,860
of that now.

77
00:06:21,860 --> 00:06:29,390
Instead of bringing it out, let's insert these dots on into our PDF into a new PDA document.

78
00:06:31,130 --> 00:06:34,250
For that, we need to import from F PDF import.

79
00:06:36,490 --> 00:06:38,680
EPRDF then.

80
00:06:40,720 --> 00:06:43,210
We need to create a new instance for that.

81
00:06:43,780 --> 00:06:47,920
But one instance correspond to one PDA file.

82
00:06:48,250 --> 00:06:51,620
And we want three PDF files in this case.

83
00:06:51,640 --> 00:06:54,940
We have three rows, three animals, three PDF files.

84
00:06:55,210 --> 00:06:58,780
Therefore, for each iteration we want to insert here.

85
00:07:00,190 --> 00:07:01,840
We want to create that instance.

86
00:07:02,050 --> 00:07:03,490
So PDF?

87
00:07:06,040 --> 00:07:13,600
Orientation to pee, so portrait mode we cover, that's in the previous lecture, so you need to take

88
00:07:13,600 --> 00:07:16,270
that lecture if you didn't do so already.

89
00:07:17,230 --> 00:07:19,010
The units over the phones.

90
00:07:20,790 --> 00:07:28,240
And the other elements would be in petty points and the formats would be an eye for.

91
00:07:29,850 --> 00:07:33,900
Then we'll add a page to the PDF.

92
00:07:34,260 --> 00:07:35,790
It's an empty page from now.

93
00:07:36,480 --> 00:07:40,110
So then next, let's add the first.

94
00:07:41,200 --> 00:07:41,830
Item.

95
00:07:43,260 --> 00:07:44,820
Contents in the PDF.

96
00:07:44,970 --> 00:07:50,220
So we said that we want the ads in the PDF page, we want to add content from top to bottom.

97
00:07:50,580 --> 00:07:54,780
So the first thing I want to add is some sort of a title.

98
00:07:55,320 --> 00:08:03,270
And I do have the codes from the previous lecture to add to the title, which works like this I'm going

99
00:08:03,270 --> 00:08:04,200
to paste this year.

100
00:08:04,950 --> 00:08:06,270
So that is the codes.

101
00:08:06,390 --> 00:08:08,690
We said the font times.

102
00:08:08,700 --> 00:08:14,820
It's a big fonts, 24 points in size and then we add the cell.

103
00:08:17,950 --> 00:08:24,700
So the text was static aesthetics, three Malayan Tiger, but we want to make this dynamic now, so

104
00:08:24,700 --> 00:08:30,430
instead of Malayan Tiger, we will add here room.

105
00:08:32,760 --> 00:08:34,710
Name no.

106
00:08:35,130 --> 00:08:39,750
If I just call Alt Foods right now.

107
00:08:40,289 --> 00:08:43,650
And as the name, I'll use an ashtray.

108
00:08:44,280 --> 00:08:48,810
So to make it dynamic, I'll do again rule.

109
00:08:51,920 --> 00:08:52,610
Name.

110
00:08:53,670 --> 00:09:01,680
And outside the curly brackets, so that will be replaced by name or by the name of the animal, which

111
00:09:01,680 --> 00:09:04,190
is, for example, American Black Bear.

112
00:09:04,710 --> 00:09:08,850
And then at the end, all at that PDAF and run this.

113
00:09:10,690 --> 00:09:13,210
And there we go, we get to three --.

114
00:09:13,630 --> 00:09:18,580
That's a first title, the second title Bumblebee and the third title.

115
00:09:19,060 --> 00:09:21,100
Now let's add those dots on down here.

116
00:09:22,780 --> 00:09:30,430
Again, I have a code from the previous lecture cockpits on my clipboard, so I'm going to add it's

117
00:09:30,760 --> 00:09:36,220
between this cell and the outputs methods.

118
00:09:37,960 --> 00:09:38,740
So somewhere here.

119
00:09:39,890 --> 00:09:45,170
Indented properly to be on the for loop.

120
00:09:45,860 --> 00:09:54,740
So what we have got here is we add the text kingdom, and next to that we adds a type of kingdom which

121
00:09:54,740 --> 00:09:55,970
is on the model year.

122
00:09:56,800 --> 00:10:04,000
Now this is the label, so that's the name of the column.

123
00:10:05,890 --> 00:10:12,820
So what we will do is we will just leave it Kingdom, so that's the next column.

124
00:10:15,550 --> 00:10:17,350
Event change this.

125
00:10:18,480 --> 00:10:19,830
To borrow.

126
00:10:23,220 --> 00:10:23,660
King.

127
00:10:24,570 --> 00:10:28,890
That's the name of the column, so that's just a label.

128
00:10:29,160 --> 00:10:32,070
We will insert that as simple text.

129
00:10:32,340 --> 00:10:37,770
But this will get the value from the current row.

130
00:10:38,550 --> 00:10:46,170
So of iteration goes like you, the first iteration we we are working on the first rule, which is.

131
00:10:48,480 --> 00:10:49,770
Four million, Tiger.

132
00:10:50,100 --> 00:10:56,090
And so we get the name for the Malayan tiger here, and then we get the kingdom for the Malayan tiger

133
00:10:56,100 --> 00:10:59,670
in here and everything is written in this --.

134
00:11:00,270 --> 00:11:01,410
So the they run this.

135
00:11:04,000 --> 00:11:05,260
And check again.

136
00:11:05,560 --> 00:11:13,180
So American Black Bear Kingdom, Animalia, all the animals are obviously the same kingdom, so everything

137
00:11:13,180 --> 00:11:13,960
is working fine.

138
00:11:14,500 --> 00:11:19,120
We can keep adding rows like that's here.

139
00:11:19,870 --> 00:11:22,450
So I'm replicating that.

140
00:11:24,070 --> 00:11:28,120
And then the next column would be Finland.

141
00:11:30,740 --> 00:11:32,410
And then here we see.

142
00:11:33,970 --> 00:11:34,520
Fill them.

143
00:11:35,080 --> 00:11:39,430
So this will work if we keep doing that for all the columns.

144
00:11:39,610 --> 00:11:48,070
But since we're working on automation, it doesn't make much sense to keep repeating ourselves here

145
00:11:48,070 --> 00:11:48,730
with the codes.

146
00:11:49,270 --> 00:11:51,550
So I think we can do better and.

147
00:11:52,730 --> 00:11:55,760
Automates this as well.

148
00:11:58,800 --> 00:12:00,480
So what I'll do is.

149
00:12:01,490 --> 00:12:04,100
Just after we aired the title in here.

150
00:12:05,200 --> 00:12:08,920
So that's for the title of a sponsor.

151
00:12:09,940 --> 00:12:14,050
After that, I will insert a new full loop.

152
00:12:14,740 --> 00:12:16,630
Let me see how we can do that.

153
00:12:17,050 --> 00:12:20,260
So just off the title, you see wrong name here?

154
00:12:20,770 --> 00:12:26,080
I'll say full column in RDF columns.

155
00:12:27,550 --> 00:12:36,700
So I'm iterating over the column names because of that's columns is of this series, which gives us

156
00:12:36,850 --> 00:12:38,020
all the column names.

157
00:12:38,320 --> 00:12:41,890
But if we do four column in.

158
00:12:44,750 --> 00:12:46,070
Do you have those columns?

159
00:12:49,170 --> 00:12:50,880
And we print the column here.

160
00:12:51,330 --> 00:12:54,300
We get access to all those columns.

161
00:12:54,690 --> 00:12:56,030
These are all strings.

162
00:12:56,040 --> 00:12:56,340
No.

163
00:12:59,600 --> 00:13:01,010
And if we do.

164
00:13:02,780 --> 00:13:09,710
Full column in columns from the second column up to the loss column.

165
00:13:12,080 --> 00:13:21,170
Print column that will print out all the columns, but the first one you see name is here, but it's

166
00:13:21,170 --> 00:13:23,300
not here because we exclude it name.

167
00:13:23,450 --> 00:13:24,950
So when you see that?

168
00:13:26,510 --> 00:13:36,320
You are slicing that, least by by taking only those items, not the item with index one.

169
00:13:37,880 --> 00:13:42,050
So let's make use of that for the loop in here.

170
00:13:42,170 --> 00:13:48,110
See, uh, one to the end and then.

171
00:13:49,240 --> 00:13:56,170
Instead of putting these texts in here, we make it dynamic, we see column.

172
00:13:57,530 --> 00:14:06,080
So, Kingdom, and if you want, you can make it a type of case, so it will be something like Kingdom,

173
00:14:06,960 --> 00:14:13,850
the title and key will be capitalized, so it's title.

174
00:14:14,960 --> 00:14:21,320
And if you want to keep the the column here, then you want to use f string.

175
00:14:21,320 --> 00:14:24,320
So f they're like that.

176
00:14:27,170 --> 00:14:33,590
Put that in curly brackets, so that's a dynamic part of a string.

177
00:14:33,860 --> 00:14:35,450
And then we have the static force.

178
00:14:35,660 --> 00:14:36,620
It's just a column.

179
00:14:38,090 --> 00:14:48,470
After Kingdom and then we go here, so this no kingdom is again replaced by column because column in

180
00:14:48,470 --> 00:14:56,730
the first iteration, a sequel to Kingdom, and that allows us to delete all these other ones.

181
00:14:58,010 --> 00:14:58,470
Right.

182
00:14:58,940 --> 00:15:06,770
We have this other line here, which means we have to indent this to make it synthetically correct.

183
00:15:07,880 --> 00:15:13,850
So that's indented under the first full loop and that's indented under the second full loop.

184
00:15:14,600 --> 00:15:23,330
Of course, we didn't include this part in the second for Loop because we have to create one PDF documents

185
00:15:23,330 --> 00:15:32,060
for each role, but then under the iteration of each arrow, we want to do something repetitive in each

186
00:15:32,060 --> 00:15:36,650
document, and the generation of the title is not repetitive.

187
00:15:37,010 --> 00:15:40,970
But this code was repetitive, so we had to include it in a full look.

188
00:15:41,850 --> 00:15:43,310
Um, let's run this.

189
00:15:45,980 --> 00:15:48,380
And let's check now looks good.

190
00:15:49,930 --> 00:15:52,550
Kingdom films class orders of honor.

191
00:15:52,990 --> 00:15:55,000
That's for the American Black Bear.

192
00:15:55,300 --> 00:15:56,890
Let's see for Bumblebee.

193
00:15:56,890 --> 00:15:57,170
Yeah.

194
00:15:57,880 --> 00:16:01,180
We have other does all the classes in sector, obviously.

195
00:16:03,870 --> 00:16:10,710
And that's how we can create multiple PDAF reports via Python.

196
00:16:11,370 --> 00:16:16,140
If you're working with these results are, of course, you can just change these to release GSV and

197
00:16:16,140 --> 00:16:19,650
then provides you the link to your see as file.

198
00:16:19,980 --> 00:16:23,490
The path to your see is a file, and that should do it.

199
00:16:24,120 --> 00:16:26,250
So thank you for following, and I'll talk to you later.

