“Where Tim Hortons is, that’s my home.” Tim Hortons, a Starbucks-like coffee shop founded by a hockey player, always has special meanings for Canadians. It is Canada’s largest fast-food restaurant chain with 4,846 stores in 14 countries, by December 31, 2018, according to Wikipedia. In this article, we will use a dataset of Tim Hortons Locations from Kaggle to show how to create interactive visualizations of latitude and longitude on maps with Plotly and Python. From these plots, we can easily answer a question:
Which Tim Hortons is the one Santa Claus usually visits?
Load the dataset:
Keep only the columns we need in this project:
Check if there are missing values:
As we saw, there are 4346 entries with no missing values.
Plot all stores on a world map:
import plotly.express as pxfig = px.scatter_geo(df,lat=df.latitude,lon=df.longitude,hover_name="_id",scope='world')fig.show()# Save the image
fig.write_image("./TimHortonsOnWorldMap.png", width=1200, height=800)
As illustrated in the image, the addresses from the dataset are mostly in North America. So that it is not a complete dataset for all Tim Hortons globally as it was claimed in Kaggle. It doesn’t matter to us because the purpose of this article is to demonstrate how to plot Lat and Long on the maps. If you are interested in a complete dataset of all Tim Hortons, I would suggest scraping the information using Google Map API directly.
Clean the data:
There are two dots far away from others. Let’s take a closer look.
As shown above, these two stores are located in North America, but the Lat and Long values are wrong. We can remove them from the dataset.
A quick EDA:
The code checked the address and created a new column ‘country’ to save the county where the stores located at. There are 3749 stores in Canada and 595 in the US from this dataset.
The chart returned the largest and smallest values of latitude and longitude.
A ‘fancy’ Plot with
Here we create another plot to show how to use
In the code, we specified the scope = ‘north america’, and the marker symbol = ‘square’.
Check the northernmost Tim Hortons:
restaurant_70237 is the northernmost Tim Hortons in the world. Even the dataset is not complete, I believe it is after verified the result on Google Map. Let’s check for the details:
As shown in the address column, it is a Tim Hortons located in Nunavut. Yes, Nunavut!!
Nunavut is the closest inhabited place to the North Pole in the world. It is also known for its indigenous Inuit people’s carvings and handmade clothing. If Santa Claus likes Tim Hortons (“I like it!” — from Santa who is studying machine learning), this location is the nearest to his home 🎅🎄👏
In this article, we learned how to create interactive geographical scatter plots on world maps using Plotly and Python with a dataset of Tim Hortons locations. Congrats! Now, let’s head to Nunavut and have a coffee with Santa.