1
00:00:02,820 --> 00:00:11,040
If you ever need to extract a table from a PDF file and save the table in a proper tabular format,

2
00:00:11,040 --> 00:00:14,370
such as a CSB file, then this is how you do it.

3
00:00:15,630 --> 00:00:21,300
And this video from this table in this PDA of documents, you can find this document attached in the

4
00:00:21,300 --> 00:00:22,230
lecture resources.

5
00:00:22,470 --> 00:00:30,090
So I'll go to my programming environments and I've uploaded the documents, the PDA of documents here

6
00:00:30,510 --> 00:00:32,009
in my project directory.

7
00:00:32,340 --> 00:00:40,080
So this might mean that's profile, and I'm going to import the library that extracts tables from PDF

8
00:00:40,080 --> 00:00:40,500
files.

9
00:00:41,550 --> 00:00:45,090
Now you'll need to install this with PIP install.

10
00:00:46,750 --> 00:00:49,450
So I am in the shell here, not in the council.

11
00:00:50,230 --> 00:00:51,850
So you need to write time, you lot.

12
00:00:53,150 --> 00:01:01,130
That's why and then imports Tabula, so I showed you that because you shouldn't install tabula, but

13
00:01:01,130 --> 00:01:03,200
tabula dash P. Y.

14
00:01:04,010 --> 00:01:05,960
So that's the proper installation.

15
00:01:07,180 --> 00:01:07,960
Execute, that's.

16
00:01:09,430 --> 00:01:14,950
Was that library installed then we are ready to write the code, which is very minimalistic.

17
00:01:16,150 --> 00:01:25,300
All you have to do is create a variable such as table and then write tabular dot reads PDF.

18
00:01:25,840 --> 00:01:28,540
Now this method gets through arguments.

19
00:01:28,870 --> 00:01:37,060
The first one being the path to the PDF document, which is whether the PDF and the second argument

20
00:01:37,060 --> 00:01:44,410
is the number of the page where the table is located, so pages equal to one.

21
00:01:45,600 --> 00:01:52,110
That is the first page in the documents, if you had a table in the second page, then you want to also

22
00:01:52,110 --> 00:02:00,600
have a right to hear or if you have multiple pages, you have to write different several read PDF lines.

23
00:02:00,900 --> 00:02:05,280
So like that one and to all implement a loop.

24
00:02:05,940 --> 00:02:15,030
So for I in range one to 10, if you have 10 pages, for example, and then writes, I hear so.

25
00:02:16,160 --> 00:02:21,860
The standard way of looking both in this case, I just want to show you a minimalistic example.

26
00:02:22,280 --> 00:02:29,510
So page number one and then putting the table run.

27
00:02:30,800 --> 00:02:31,610
And there we go.

28
00:02:33,530 --> 00:02:35,060
Yeah, that's the the output.

29
00:02:36,710 --> 00:02:44,780
Year, month and day out temperature pressure for her noid, so we have these columns here and each

30
00:02:44,780 --> 00:02:50,420
of them have built up not what type of object is this table?

31
00:02:50,780 --> 00:02:59,060
Well, you see a listes here and opening brackets, which means that this is a list, but this list

32
00:02:59,060 --> 00:03:00,500
has only one object.

33
00:03:01,430 --> 00:03:03,650
That object is a data frame.

34
00:03:04,010 --> 00:03:07,370
So the output is a list of data frames.

35
00:03:07,610 --> 00:03:12,710
If we had more than one tables, we would have a list of more than one data frames.

36
00:03:12,950 --> 00:03:15,770
In this case, we have only one list with one item.

37
00:03:16,160 --> 00:03:18,560
That item is for single data frame.

38
00:03:20,180 --> 00:03:29,420
So that means if you just do here, table zero, you stroked the table without the list, so that's

39
00:03:29,420 --> 00:03:30,680
the second ultimate we got.

40
00:03:31,280 --> 00:03:32,810
You see, there's no list here.

41
00:03:33,050 --> 00:03:40,730
And if you do print type of that table table zero.

42
00:03:41,790 --> 00:03:45,270
You see that this is a pandas dataframe in here.

43
00:03:46,470 --> 00:03:53,820
So we can make use of that and convert this table to table zero.

44
00:03:54,360 --> 00:04:01,200
We can convert it to Sears V. So to Sears V. is a method of pandas.

45
00:04:01,380 --> 00:04:10,590
So since this is a pandas dataframe because tabula, this library installed pandas on the big grounds.

46
00:04:11,130 --> 00:04:14,010
So it is able to generate these tables.

47
00:04:14,250 --> 00:04:18,529
So since this is a data sharing table, it does have access to sources methods.

48
00:04:19,140 --> 00:04:21,360
So defined the outputs.

49
00:04:22,450 --> 00:04:28,470
File path out from the CSB, for example, and run.

50
00:04:30,070 --> 00:04:33,400
And you should expect a certain file being generated in here.

51
00:04:33,680 --> 00:04:38,440
No, we see that we do have this comma here.

52
00:04:39,520 --> 00:04:48,370
So Python, what Python does is it adds an index column on the Left of the Year column here.

53
00:04:49,470 --> 00:04:55,710
And you can see that in here, so it's added this zero one two three four five six.

54
00:04:55,920 --> 00:05:01,240
If you don't want that, then you can specify an index is equal to none.

55
00:05:01,260 --> 00:05:06,180
So you don't want an index column around that and that will override the previous output.

56
00:05:06,180 --> 00:05:06,960
That's useful.

57
00:05:06,960 --> 00:05:10,770
And now you don't have that index column, so.

58
00:05:13,180 --> 00:05:18,640
Those are the dots, as you see the loss of row here, you have emptied out Tacoma, Tacoma, comma,

59
00:05:18,650 --> 00:05:24,070
comma, so no data, but we have 5.0, which reflects the formats here.

60
00:05:24,070 --> 00:05:33,430
So we don't have data in this last row, but we do have this five in the last column and that is reflected

61
00:05:34,030 --> 00:05:36,190
quite well in the design here.

62
00:05:37,010 --> 00:05:38,470
Oh, that is a complete code.

63
00:05:38,710 --> 00:05:39,550
Thank you for calling.

64
00:05:39,580 --> 00:05:40,360
I'll talk to you later.

