How much of a role can ecosystem restoration play in tackling climate change?

Global warming is likely to play a major role in the extinction of many species in this century. The Intergovernmental Panel on Climate Change (IPCC) says an average temperature rise of 1.5 degrees…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Easily create GeoJSON file from Pandas data frame

Have you ever been wondering how to create a beautiful map visualization without hours of struggling with different libraries? But almost every time you don`t have exactly what you need from the beginning. Here I describe a convenient approach how to prepare necessary data.

My favorite library for this purpose is Plotly. This tool is very easy to learn and use in projects. But if you want to master it, this will take some time.

In this article, I am going to describe the methods to build a file with stored polygon coordinates with different geometry from the prepared Pandas data frame.

This is an example of the desired data frame with regions. In the first step, I will create lists with coordinates of latitude and longitude for each point and add them into the right-built GeoJSON file.

We are going to create the GeoJSON file from a dictionary. It consists of the main elements: “type”: “FeatureCollection” and “features”:[]. The coordinates will be stored in the features list. Every feature has the following attributes: type, properties, and geometry. In the properties, it could be mentioned any information about region id, zip code. The geometry block is necessary to determine the type of object and its coordinates. Below you can see a function to build such a dictionary.

Now, it will be very easy and convenient to create any GeoJSON file and built a beautiful map visualization. Below, I provide a code snippet with mean trips for yellow taxis in New York.

Choropleth Map with Plotly: Mean trips of yellow taxis in New York

With this script, you can easily create your own GeoJSON file and represent complex polygons on the map. Maybe, this is not the most sophisticated method, but it is 100% working. Hope, to see your data visualization masterpieces.

Add a comment

Related posts:

Stardate S02E29

Had another lucky Thursday catching so many folks in the office. Strategy chats with Jon, Harri and Liam was the main agenda — we discussed the ‘law’ of attraction at one point, I’m wondering if that…

The Active Reader

When it comes to reading newspapers or print magazines I have to confess that it’s not something I do on a daily, weekly or even monthly basis. The internet particularly social media sites, Twitter…

Japanese is One of the Hardest Graduate Programs

Being a student in the Master’s program for translation in Japanese is no easy task. The two-year Master of Arts program covers different areas in translation beyond day-to-day conversations such as…