1
00:00:00,030 --> 00:00:04,500
Hello! In the previous lecture you were
able to build this map with multiple

2
00:00:04,500 --> 00:00:09,690
markers. This map happens to have only
two markers, but you get the idea and the

3
00:00:09,690 --> 00:00:15,870
script was this one here, so you can add as
many coordinate pairs as you want in

4
00:00:15,870 --> 00:00:20,880
here, but in this lecture I want to show
you how to add pairs of coordinates out

5
00:00:20,880 --> 00:00:31,320
of a text file which is this one here.
Volcanoes.txt. If you like you can

6
00:00:31,320 --> 00:00:36,809
just rename the name of this from
Volcanoes.txt to Volcanoes.CSV and

7
00:00:36,809 --> 00:00:42,809
then you can open it in a program such
as Excel. If you like you can show it on

8
00:00:42,809 --> 00:00:48,840
a plain text file as I'm doing it being
here. Python can read both CSV and text

9
00:00:48,840 --> 00:00:54,570
files, so what we have here are some data
about volcanoes basically we have the

10
00:00:54,570 --> 00:01:02,789
number of the volcano which is some sort
of ID, so volcano 020. We have yet

11
00:01:02,789 --> 00:01:10,680
another number then, and as you see every
column, so we have columns in this data

12
00:01:10,680 --> 00:01:15,810
file and every column is separated by
a comma. This is the name of the first

13
00:01:15,810 --> 00:01:20,100
column which is, which for the first
value of this first column is this one

14
00:01:20,100 --> 00:01:24,900
here. Then there is the name of the second
column, the first value of the second

15
00:01:24,900 --> 00:01:29,939
column is this one here, then the second
value of the second column is this and so

16
00:01:29,939 --> 00:01:37,710
on, and then we have the name column, the
name or the volcano in here. Sorry the

17
00:01:37,710 --> 00:01:46,380
name is here, Baker and the comma starts
here which means that location is this

18
00:01:46,380 --> 00:01:53,299
here, US Washington. Then you have the status,
status historical for the first volcano,

19
00:01:53,299 --> 00:01:59,399
and then we have the elevation which is
this one in here. I'm not sure whether

20
00:01:59,399 --> 00:02:04,469
these are in feet or meters, but you can
find out. If you've curious you can do

21
00:02:04,469 --> 00:02:11,009
research for this particular volcano and
compare the elevation. Anyway, and then we

22
00:02:11,009 --> 00:02:13,640
have the type of the volcano.
Then you have the time frame

23
00:02:18,310 --> 00:02:27,610
which is D3. I'm not sure
what this means. D4 and so, then

24
00:02:27,610 --> 00:02:32,970
lastly this is what we are interested
about, we have the lat and long columns.

25
00:02:32,970 --> 00:02:40,810
So this is a lat which means latitude,
and this is the longitude of the volcano.

26
00:02:40,810 --> 00:02:46,690
So you need these two numeric values in
order to map the features, so the

27
00:02:46,690 --> 00:02:54,420
volcanoes into a map, in this case into
a Folium map, so this has around 63,

28
00:02:54,420 --> 00:03:04,000
actually 62. 63 including the header of
the data and so how do we load this file

29
00:03:04,000 --> 00:03:12,780
into Python? Well, to load that file into
Python, let me clear the terminal and

30
00:03:12,780 --> 00:03:19,720
you'd first need to install a very
useful library called Pandas. We're going

31
00:03:19,720 --> 00:03:25,060
to use this library later on, so I'm not
going to explain Pandas in detail for

32
00:03:25,060 --> 00:03:30,700
now because we were just using one or
two of its functions which I'll explain

33
00:03:30,700 --> 00:03:33,640
in this lecture.
So go ahead and install Pandas if you don't

34
00:03:33,640 --> 00:03:39,400
have Pandas. Pip install Pandas or pip3
install Pandas depending on how you

35
00:03:39,400 --> 00:03:46,799
have configured Python, and then you
can go ahead and open a Python session.

36
00:03:46,799 --> 00:03:54,489
Import Pandas and the way to load a file
with Pandas is by pointing to pandas.read

37
00:03:54,489 --> 00:04:03,340
CSV volcanoes.txt.
Make sure that your Python session has

38
00:04:03,340 --> 00:04:10,000
been opened in the directory where your
volcanoes.txt file is, so for

39
00:04:10,000 --> 00:04:15,280
recess my session is inside mapping
folder which is this one here, so I can

40
00:04:15,280 --> 00:04:18,209
just pass the file name.
Otherwise you may have to pass the

41
00:04:20,379 --> 00:04:27,159
absolute path of the file which starts from
like C slash slash and so on depending

42
00:04:27,159 --> 00:04:34,330
on what operating system you are in.
Execute that and call data and you get

43
00:04:34,330 --> 00:04:39,539
the data printed out. Just like that.
So Pandas is able, actually the read

44
00:04:43,000 --> 00:04:50,560
method is able to distinguish between
these comas where the commas are and so

45
00:04:50,560 --> 00:04:59,490
it creates a well-structured data format
with columns so if you go down here,

46
00:04:59,490 --> 00:05:07,270
so you have some columns here, column,
column, column and then up to the end, but

47
00:05:07,270 --> 00:05:12,370
then you have other columns because
Python cannot print out, actually the

48
00:05:12,370 --> 00:05:17,740
terminal doesn't allow you to have all
the columns in one, inside this

49
00:05:17,740 --> 00:05:22,419
area here because it would be too much.
Anyway you have status, elevation, type,

50
00:05:22,419 --> 00:05:29,940
timeframe, lat
and lon, so that's about the data.

51
00:05:29,940 --> 00:05:38,050
Now you need to figure out a way to
iterate through that data frame, so this

52
00:05:38,050 --> 00:05:45,430
is called a data frame, so the data
object is called a data frame. You can

53
00:05:45,430 --> 00:05:56,020
check its type actually. Pandas.core.
frame.DataFrame. So what I'm thinking of

54
00:05:56,020 --> 00:06:05,650
is to actually create two list out of
these data frame columns, so to put the

55
00:06:05,650 --> 00:06:11,069
latitude column in a Python list, and the
longitude column in another Python list.

56
00:06:11,069 --> 00:06:15,550
And so that we have a native Python
object which is a list and then we can

57
00:06:15,550 --> 00:06:25,919
iterate through that list using the for
loop, so let me try to do that.

58
00:06:26,399 --> 00:06:34,490
Import Pandas,
then create the data frame object,

59
00:06:34,490 --> 00:06:39,880
so loading the data read CSV
Volcanoes.txt.

60
00:06:39,880 --> 00:06:47,600
And yeah, that's it.
So how do we convert a data frame column

61
00:06:47,600 --> 00:06:54,890
into list? Well, the way to do that is by
just doing let's say L or lat equals to

62
00:06:54,890 --> 00:07:04,010
data and then the name of the column which
is lat, so you can get the list of

63
00:07:04,010 --> 00:07:09,310
columns by the way by doing data columns.
Here you see you have a lat and a lon

64
00:07:13,490 --> 00:07:26,270
column and then you do lat equals
to list, data Lon in square

65
00:07:26,270 --> 00:07:33,890
brackets, close it. And so what you did
here is data with the lon attribute

66
00:07:33,890 --> 00:07:40,160
there will turn a series object, but
that series object we are converting it

67
00:07:40,160 --> 00:07:50,240
into a native list, so that will be a
Python list. This would also show up as

68
00:07:50,240 --> 00:07:59,030
a similar object. So this is a series
object and this is a list, but I prefer

69
00:07:59,030 --> 00:08:04,520
to work on a list because it working on
lists is faster then working on data

70
00:08:04,520 --> 00:08:15,580
frame series, so the idea is to have two
lists here. That equals to list data lon.

71
00:08:15,580 --> 00:08:25,130
Copy that, paste it here, and the same
thing goes for longitude, so lon,

72
00:08:25,130 --> 00:08:28,300
lat and lon lists.
So now we need to be careful here on how

73
00:08:33,750 --> 00:08:40,050
we iterate through these two lists because
you know what we have is we have two

74
00:08:40,050 --> 00:08:46,200
lists and each of them has 62 items, you
can check that using the len here, down

75
00:08:46,200 --> 00:08:54,710
here and lat. So it has 62 items and
the same goes for the longitude list.

76
00:08:54,710 --> 00:09:00,810
That means that the first item of the
latitude list corresponds to the second

77
00:09:00,810 --> 00:09:05,460
item on the latitude list, sorry of the
longitude list. So the first two items

78
00:09:05,460 --> 00:09:12,720
make up the first location of the first
marker. That means that in the first

79
00:09:12,720 --> 00:09:18,240
iteration we need to extract both
locations, so actually this sort of

80
00:09:18,240 --> 00:09:23,490
structure won't be appropriate anymore.
What you need to do is you need to go

81
00:09:23,490 --> 00:09:30,780
through let's say lat and lon variables.
In, when you iterate through two lists

82
00:09:30,780 --> 00:09:36,930
and at the same time you need to use the
zip function and that goes lot and

83
00:09:36,930 --> 00:09:44,640
lon, so basically what this function
does is like this.

84
00:09:44,640 --> 00:09:50,570
Let's say for I, J in zip.
Let's say the first list is 1, 2, 3 and

85
00:09:52,250 --> 00:10:12,950
the second is 4, 5, 6. Print I and J, so
this is what happens. This loop will go

86
00:10:12,950 --> 00:10:17,790
through these two lists at the same time,
so what happens is that I will go

87
00:10:17,790 --> 00:10:23,400
through the first item of the first list
while J will go through the first item of

88
00:10:23,400 --> 00:10:31,260
the second list. And so in the first
iteration 1 and 4 are extracted, so 1

89
00:10:31,260 --> 00:10:39,510
here and 4 here. And you can do such an
extraction by using the zip function.

90
00:10:39,510 --> 00:10:45,150
Otherwise you won't be able to do that
if you don't use the zip function, so zip

91
00:10:45,150 --> 00:10:50,660
sort of distributes the items one by one.
And so the same goes here.

92
00:10:50,660 --> 00:10:57,030
Lt will get the first item of this list,
l1 will get the first item of this list,

93
00:10:57,030 --> 00:11:05,880
and then here what you need to do is you need
to construct a list with lt and ln, yeah.

94
00:11:05,880 --> 00:11:14,610
That's it. Save the script, go to the
terminal to execute. It's not here the

95
00:11:14,610 --> 00:11:26,760
terminal. I'll just exit that. Python3
map1.py execute. No errors.

96
00:11:26,760 --> 00:11:29,450
Go to Firefox and reload.
I've got no markers for some reason, but

97
00:11:36,090 --> 00:11:40,830
I didn't get an error so this is one of
those scenarios where you don't get an

98
00:11:40,830 --> 00:11:45,320
error in the terminal so in that case
you need to double check your code

99
00:11:45,320 --> 00:11:56,100
carefully. So data pandas.read.csv.
Lat list data. Lon, here the error, so what's

100
00:11:56,100 --> 00:12:05,220
happening with that I'm assigning the
wrong column to the latitude list, so

101
00:12:05,220 --> 00:12:13,110
let me change the order and try again.
So don't get intimidated by errors. Errors

102
00:12:13,110 --> 00:12:19,140
happen all the time you just needed to
be cold-blooded and read the errors if

103
00:12:19,140 --> 00:12:27,090
you get any error here and also look at
the code carefully. Let me reload. I've

104
00:12:27,090 --> 00:12:35,640
got some markers now. So these are the
locations of volcanoes in North, in US

105
00:12:35,640 --> 00:12:46,380
actually, United States. Okay. I also have
this pop-up which is working well, but I

106
00:12:46,380 --> 00:12:50,220
assume you don't like it very much
because it's not showing any information.

107
00:12:50,220 --> 00:12:55,390
So what we need to do
here is to actually make this pop-up

108
00:12:55,390 --> 00:13:01,740
dynamic so that it shows some actual
information, and I'll show you how to

109
00:13:01,740 --> 00:13:06,000
create dynamic pop-ups in the next video.
Talk to you there!

