Creating mapview of crime data using Folium

Shaliniktyagi
3 min readJun 30, 2021

Cleaning and exploring the data are quite common and important tasks in the field of data science. In this field, people spend more time preparing data in comparison to fit the machine learning model.

In this post, I am taking you through basic preprocessing which is required to create a map by using Folium in python. I used the UK Crime data to predict the likelihood of an offense being prosecuted. In this post, I will cover how to create a geospatial map to see the hotspots of the different crime types based on the location.

Overview of the data

This blog explains the data received from the Hertfordshire constabulary which can be downloaded at https://data.police.uk/data/. As a first step, I imported few libraries which will be used to load, explore and visualize the data.

Let’s see the few rows of this dataset. I can see that this data has 12 columns that have categorical data except for Latitude and Longitude. At a glance at the data, I can see context is an empty column with no values. so I have decided to delete that column from the data frame.

I want to see the basic summary of each column in the data and see how many null values are in the data frame. As we can see that some columns have missing values. So I deleted these rows from the data frame. However, there are other ways to deal with null values in a data based on the analysis that I will discuss in the next post of this series.

Plotting maps with Folium

It is easy to explain the map in python because you can zoom in and zoom out the map with the + and — symbols in the top left corner. In this map, I have looked at the locations for the different crimes in the year 2020. However, I can entail further to see the particular crime type location in a specific month and year.

Conclusion

In this post, I have shown you how to build the map with folium in python on UK crime data. For this project, you can check out my GitHub repository to see the full code which I used to build this project.

I hope this post will help you.

Thanks for taking the time to read it.

--

--

Shaliniktyagi

I am a data scientist and passionate about data science | Bringing new insights from big data intrigues me.