1
00:00:02,330 --> 00:00:10,940
Hi, in this video will be filtering out file names, so for this example, I have this file folder

2
00:00:11,270 --> 00:00:12,620
in my working directory.

3
00:00:12,890 --> 00:00:17,880
So I invite you to create a similar folder named files.

4
00:00:18,140 --> 00:00:22,420
And inside that folder, please put these text files.

5
00:00:22,430 --> 00:00:28,130
You can find these files attached in the intellectual resources and upload them in your files directory.

6
00:00:28,850 --> 00:00:37,700
So let's suppose that these are bills pointing to different deeds or so, but the naming of these files

7
00:00:38,240 --> 00:00:39,290
is not that good.

8
00:00:39,350 --> 00:00:47,810
As you see, the personal name them did not use the best practices to name files, but that is why regular

9
00:00:47,810 --> 00:00:48,920
expressions exist.

10
00:00:49,490 --> 00:01:01,460
So our goal here is to filter only those bills from 1st of November on to the 20th of November.

11
00:01:01,490 --> 00:01:04,730
That means we want to extract this first file.

12
00:01:04,739 --> 00:01:15,980
Nov 13 The 2nd Nov 12 Nov 22 Not this one, because this is after November 20th, then we want to see

13
00:01:15,980 --> 00:01:16,760
this as well.

14
00:01:17,330 --> 00:01:18,680
November 14th.

15
00:01:19,040 --> 00:01:21,740
Not this, not October.

16
00:01:21,860 --> 00:01:24,710
So only the first one of the second and the third one.

17
00:01:25,040 --> 00:01:29,520
Let's see how we can do that before we write the regular expression.

18
00:01:29,780 --> 00:01:32,720
We want to get a list of these files.

19
00:01:32,900 --> 00:01:34,640
For that, we want to use.

20
00:01:36,490 --> 00:01:37,540
The path.

21
00:01:39,870 --> 00:01:46,140
Class of the past Liberal Library, if you don't know what this is, you need to go back to the calls

22
00:01:46,140 --> 00:01:51,300
and take the file and folder operations sections.

23
00:01:52,200 --> 00:01:54,960
There I introduce you to the path of the library.

24
00:01:55,260 --> 00:02:04,890
So then we want to create a root directory, which points to the folder where the files are located.

25
00:02:05,370 --> 00:02:07,740
So files is the name of the folder.

26
00:02:08,250 --> 00:02:10,410
Once we have that, we can create a list.

27
00:02:10,419 --> 00:02:16,170
File names, a single two routes do those eight to do.

28
00:02:17,890 --> 00:02:24,610
And let's print out financier converted into a list because it's a generator objects.

29
00:02:26,620 --> 00:02:29,470
That is the lease or file paths.

30
00:02:29,920 --> 00:02:32,290
There's a problem, though, these.

31
00:02:33,300 --> 00:02:35,210
Items are not strings.

32
00:02:35,300 --> 00:02:38,450
These are Paul 02:06 object types.

33
00:02:38,660 --> 00:02:40,580
So we want to convert them into strings.

34
00:02:41,600 --> 00:02:43,870
We can use a list comprehension for that.

35
00:02:44,990 --> 00:02:49,940
File names as a new variable SDR.

36
00:02:50,330 --> 00:02:57,140
So to denote that these items of this list will be strings that is equal to a list comprehension which

37
00:02:57,290 --> 00:03:05,480
would go like file name, dot name from each postfix path, we extracted the name, which will give

38
00:03:05,480 --> 00:03:11,930
us only that part for file name in file names.

39
00:03:12,290 --> 00:03:13,220
That's one.

40
00:03:14,730 --> 00:03:20,760
And let's print out file names, SDR now we're going to get on them to this here.

41
00:03:21,180 --> 00:03:30,570
That is because file names at this point of the execution is empty because a sense file names was a

42
00:03:30,570 --> 00:03:31,950
generator objects.

43
00:03:32,190 --> 00:03:38,130
That means when we converted into a list, when we converted the generator into a list that means we

44
00:03:38,130 --> 00:03:41,310
use the generators of the generator is exhausted.

45
00:03:41,730 --> 00:03:49,620
Therefore, a solution is to get to this list comprehension and also the variable called here and just

46
00:03:49,890 --> 00:03:51,210
place it in here.

47
00:03:51,990 --> 00:04:00,000
So now we generate a generator again in here and then we don't print it out, so we don't exhausted,

48
00:04:00,210 --> 00:04:04,230
but we use it in here in this list comprehension.

49
00:04:04,710 --> 00:04:06,870
This time we will get this list.

50
00:04:08,490 --> 00:04:13,590
So novelist, a story in this valuable and we can use it further.

51
00:04:13,920 --> 00:04:18,870
So let's now write for a regular expression.

52
00:04:26,010 --> 00:04:32,430
So we want to find some bills from November the 1st to November the 20th.

53
00:04:33,330 --> 00:04:41,940
That means our files will always have this no port, no some files will have a capital and so uppercase

54
00:04:41,940 --> 00:04:54,750
letter we can ignore case sensitivity using R e tort e kunwar keys as a second argument.

55
00:04:54,990 --> 00:05:01,440
So that means both north with a capital letter and north with lowercase letters will be included in

56
00:05:01,440 --> 00:05:01,860
the match.

57
00:05:02,220 --> 00:05:07,080
Sometimes, though, we have November and sometimes we have just north.

58
00:05:07,920 --> 00:05:16,350
So what we could do is we could just write a range here from A to Z and we could use a metal character.

59
00:05:16,960 --> 00:05:19,980
So zero or more times the asterisk.

60
00:05:23,090 --> 00:05:23,630
Like that.

61
00:05:24,140 --> 00:05:32,900
Then after that, we have a dash, right, so it could be no Dash or November dash.

62
00:05:33,380 --> 00:05:42,680
Then the next character could be one or two because we are filtering out only from the 1st of November

63
00:05:42,690 --> 00:05:44,810
until the 28th of November.

64
00:05:45,110 --> 00:05:54,870
So it could be no if one of two or three of four or five six seven eight nine, 10, 11, 12 and so

65
00:05:54,890 --> 00:05:55,190
on.

66
00:05:55,940 --> 00:05:58,430
So the next character is a number.

67
00:05:59,910 --> 00:06:09,710
And so we use these parentheses, so we have to use them or operators inside these like that.

68
00:06:10,160 --> 00:06:17,990
And we said the first number could be first from one to nine.

69
00:06:18,470 --> 00:06:20,510
So one, two nine range.

70
00:06:21,200 --> 00:06:30,770
So we want to work on every 10 digits whenever you want to feel two digits or numbers with regular expressions.

71
00:06:30,770 --> 00:06:33,940
So let's say one two six seven.

72
00:06:34,610 --> 00:06:41,270
You want to treat first the range from one to nine.

73
00:06:41,300 --> 00:06:48,560
So one digits, then you want to treat the next range from 10 to 19.

74
00:06:48,770 --> 00:06:49,700
Then the next.

75
00:06:49,970 --> 00:06:51,320
So that's what we're doing here.

76
00:06:51,470 --> 00:06:56,450
First, we work on the first range of numbers, so one digits from one to nine.

77
00:06:56,690 --> 00:07:04,640
We see that or it could be 10, 11, 12 until 19.

78
00:07:04,880 --> 00:07:10,070
So it could be one, followed by zero to nine.

79
00:07:10,490 --> 00:07:18,010
So one zero one one one two one three one four and two one nine.

80
00:07:18,650 --> 00:07:22,490
Then again, the vertical bar, or 20.

81
00:07:23,460 --> 00:07:32,130
So just to see if you had to go up to 23rd of November, then you do something like two of them in square

82
00:07:32,130 --> 00:07:35,430
brackets, you'd insert the range zero to three.

83
00:07:35,670 --> 00:07:39,450
So that would include 20, 21, 22 and 23.

84
00:07:39,810 --> 00:07:40,790
This is not the case.

85
00:07:40,800 --> 00:07:41,730
We just want 20.

86
00:07:41,730 --> 00:07:43,560
So 20 is fine.

87
00:07:44,070 --> 00:07:49,120
Then after that, after the number, we have four dots and the tricky part.

88
00:07:50,130 --> 00:07:57,670
So I executed that, but we haven't extracted the actual matches yet, so I shouldn't have executed

89
00:07:57,670 --> 00:07:57,810
it.

90
00:07:57,870 --> 00:07:59,130
So let's add the matches.

91
00:07:59,750 --> 00:08:01,350
Matches are.

92
00:08:02,100 --> 00:08:02,400
Hmm.

93
00:08:02,580 --> 00:08:12,330
Now we have a list here, so be careful because previously we were working on text strings, but this

94
00:08:12,330 --> 00:08:15,870
is at least steroids of your of.

95
00:08:15,870 --> 00:08:20,850
The IP addresses were coming as Texas wants single string.

96
00:08:21,090 --> 00:08:25,950
So in this case, we want to work on a list comprehension.

97
00:08:26,370 --> 00:08:39,220
We would see something like file name for file name in file names, a city or so we go through that

98
00:08:39,240 --> 00:08:40,020
list.

99
00:08:40,320 --> 00:08:47,070
But if pattern that finds full file name.

100
00:08:49,800 --> 00:08:53,460
Matches, I'll explain you, that's a list comprehension in just a bit.

101
00:08:54,150 --> 00:09:01,050
So that's the ultimate Nov 12, Nov 13 November 14th.

102
00:09:02,070 --> 00:09:03,390
No, there's not 20 here.

103
00:09:03,390 --> 00:09:09,570
So let's try to add a 20 in here in these files.

104
00:09:09,840 --> 00:09:15,690
So create a new file and let's say, Nov 20, the 16.

105
00:09:17,140 --> 00:09:25,830
Go back to the notebook and executed the first cell where we get the files from the Working Directorate

106
00:09:25,900 --> 00:09:26,710
execute that.

107
00:09:28,070 --> 00:09:34,550
So you've seen enough 20s there now, execute the other sell as well, and we get enough 20, so it's

108
00:09:34,550 --> 00:09:35,120
working well.

109
00:09:35,300 --> 00:09:37,220
But let me explain you how this works.

110
00:09:38,270 --> 00:09:40,640
So we are iterating over the file names.

111
00:09:40,640 --> 00:09:42,740
Trim lists this list here.

112
00:09:43,400 --> 00:09:52,760
File name for file name in five-string and now we will includes in the matches list only if this evaluates

113
00:09:52,760 --> 00:09:53,690
to true.

114
00:09:54,110 --> 00:10:02,420
So this evaluates to true only when the pattern is formed in the file name in the current file name

115
00:10:02,420 --> 00:10:03,800
of the iteration.

116
00:10:03,980 --> 00:10:05,690
So we iterate over these.

117
00:10:05,900 --> 00:10:12,680
So let's say first, we have this as the file name variable inside this list comprehension and we see

118
00:10:12,890 --> 00:10:17,150
is this pattern in that file name.

119
00:10:18,050 --> 00:10:24,860
So if it is, then that's file name will be included in the list, so it will be added to the matches

120
00:10:24,860 --> 00:10:25,310
list.

121
00:10:25,730 --> 00:10:28,460
Otherwise, it will not be added to that list.

122
00:10:29,150 --> 00:10:35,420
So we will end up with a matches list, which will contain only those file names which.

123
00:10:36,830 --> 00:10:47,120
Satisfy this condition here, and that concludes this video on filtering data that contain numbers,

124
00:10:47,600 --> 00:10:50,310
so thank you again, and I'll talk to you in the following videos.

