Python Folium - display restaurant address on a map

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey folks welcome back it's the last video of the burger war series again you can can watch it as a part of the series or stand alone if you're interested in how to put locations on the map so we stopped here with a list of geolocations with relative longitude values for our mcdonald's and working restaurants in paris london and berlin and now we want to put them on a map like this let's start so let's start creating a new file let's call it visualization py and first of all let's do the necessary imports so we need pandas again to read in our restaurants geo csv file uh we need volume which will be our library for creation of maps and markers and so on and we need a special plugin called marker cluster from volume we don't need it necessarily but it is a kind of cool feature for marker aggregation i will show you in a minute so with having volume imported we can already create the base map so with the folio map class we can create a new map a location basically um is the location of the map center and here i took some central place in europe tiles define the style of the map and here open street map provides some free tiles which are very beautiful and the zoom starts define how far away from this center ur and with m dot safe we can save it as an html file and have a look on it on the browser so let's execute it it's done let's move to our folder and let's open it in chrome to have a first look on it so this is our base map created with volume as mentioned we are somewhere located in in europe we can also zoom in zoom out and perhaps that's interesting to know so let's go back to the script and let's change the zoom factor here so the zoom start and execute it one more time have a look at it again compare this this was it before this is a map now so we are much closer zoomed in it's paris actually and we can do the same one more time let's use a zoom vector of one execute it again refresh it and you see now we are very far away and basically see the whole world multiple times if we zoom in we can zoom anywhere so this is the base functionality of of a map in volume now let's move on to create markers on our map but first let's let's change it back to 5 which was quite good so like this i said let's create a marker or better let's create two markers so with the folio marker class we can create a marker on a map we also need to specify a location so combination of latitude and longitude values um we can give the marker a pop-up with a text inside and we can specify the color of the icon and with the last comment here at 2 m we added to our map which we created in line 5. so i did the same twice one blue marker with the same location like the center of our map and one red marker was a little bit different ready to longitude values let's execute it and see how it looks so let's refresh our map and you see we have two markers here one direct in the center of our map in paris and one a little bit to the north we have a blue one and a red one and when we click on it we see our pop-up text that's how how to create markers next step basically would be creation of a marker for each of our values here from them from from the csv file so uh first of all to get a feeling again about our data let's read it in and print some values to the console to get a feeling about our structure of the data here again so let's quickly use pandas here to read in our csv file restaurants gu.zsv and quickly print out the first lines to the console together get a feeling again let's execute it and we see here our data frame in pandas we have the restaurant name here in the restaurant column we have the street the zip codes the city and country and then at the end the latitude longitude values which we or which are the most important for our markers but also in the pop-up we might add the restaurant text and the address again so that's what we do right now so loop through the data set and each line and create a marker for each of them alright so first let's comment those things out we don't need them right now or we can also delete this one now after we read in our data frame we need to create a loop through each of the lines so this is a comment to loops for each of the lines of the pandas data frame and basically for each of the line we then want to create a marker right so let's do this and copy it in but we don't want to create the same mark all the time and the same location was the same text and so on so um those things must be variable and will change with each of the line we are looping through right so let's remember um the columns so let's perhaps read in first the restaurant column the latitude and the longitude column and make them somehow variable so this is a comment to read in certain columns in a certain row so in the led variable we will always store whatever comes here in this column and the lng column in the lng variable we will store whatever is in the lng column and in the rest variable we will store whatever comes in the restaurant column here so this we can already use to and and put it basically in the marker so we replace the fixed values here with our variable ones and also the pop-up text we will exchange with the restaurant name let's see how this works and execute it and let's have a look in the browser and refresh it and you see we get a lot of markers here and each of them contains the restaurant name here burger king or mcdonald's in the pop-up but somehow we can't differentiate it right so they are all blue uh we somehow wanna wanna differentiate and see directly is it a mcdonald's or a burger king restaurant so perhaps let's also make the color a little bit variable so basically as we already read in the restaurant name here we can make the color dependent on the restaurant name so let's do it so whenever the restaurant's name is mcdonald's we make the color blue and when it's not mcdonald's we make it red and we need to adapt our mark here which we create for each of the line so we we simply read in the color variable here instead of giving a fixed value let's execute it and let's refresh our map this looks much better perhaps let's move in closer to paris you see we get a lot of red markers also a lot of blue ones and if we click the blue ones they should be all having mcdonald's at the pop-up text and the red one should have burger king inside great so we are nearly done let's have a look on two more details so first one if we look on our map and click on the mark we only get the restaurant's name we want to have the full address that's the first one we have a look at and then the second one we will have a quick look on the functionality of a marker cluster which is very nice and gives a good way to console the date markers so but first things first let's adapt the pop-up text so this should adapt the pop-up so we wanna somehow concatenate the restaurant's name the street name the zip and the city and for some of the rows as they contain somehow for example the zip code contains values it might be an integer or something so we need to convert it into a string that we can display it as a text so we need to change the pop-up here not to only the restaurant name but the whole pop-up string and let's save it and execute it looks good let's have a look on the map refresh let's perhaps now move into london click on a marker and we see the restaurant name burger king the street zip code and city and this is already looking very promising nice perhaps one more hint this br is a line break so it uh um just puts the next contents into the next line to make it a little bit more yeah to give a better overview now last thing let's have a look on the marker cluster before we close off the video so the marker cluster let's first of all create a mac cluster so this comment just creates a new mark cluster and we add it to our folio map and then last thing we don't add the markers directly to the map instead we add it to our created marker cluster um let's execute it quickly and again let's have a look on our map and execute it and as you can see now it summarizes the number of markers in a given um yeah in a given area and if we move closer in let's do it you see it divides the sub-areas a little bit so there's one burger king restaurant far away from the city center in berlin there are two restaurants here and if you move closer you see especially in the in the real city center of berlin there are a lot of restaurants a lot of fast food consumed here 17 restaurants overall while around the center it's it's a few less and if we move in closer we can then come to the to the real markers with uh the address and so on so that's it already there was the last video on burger wars i hope you liked the series and in future now i want to focus a little bit on different topics like mqtt kafka javascript stuff um be curious more from me soon bye bye and have a nice day
Info
Channel: Code & Dogs
Views: 4,600
Rating: undefined out of 5
Keywords: python, python3, leaflet, leaflet.js, folium, gps, longitude, latitude, programming, webdev, coding, development, 100daysofcode, webscraping, web-scraping, beautifulsoup, selenium, api, pandas, web, scraping, web scraping, web crawling, geocoding
Id: 9biKWoGK3j0
Channel Id: undefined
Length: 13min 37sec (817 seconds)
Published: Sat Nov 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.