image

Introduction

In the map above, there are too many columns showing up when I hover over one of the polygons. In this article, you'll learn how to remove the columns that you don't want and keep the ones that you do want in the dataframe.

This is a part 2 article; if you haven't already, check out my part 1 article, where I show you step-by-step how to create the map!

Specifying Certain Columns

Let's say that I want to only see 3 of the columns when I hover over the polygons: "community", "Pop2014", "Property_C". To do this, I can do this:

image

I'm keeping the "geometry" column because I need the coordinates to be able to create a map from the data.

This will get a dataframe called "file" that only shows the columns that we want: image

Displaying the Updated Map

Now we can display the map again on the property crime rates in Chicago:

image

And if I hover over the polygon, it's a lot cleaner:

image

Renaming the Columns

However, there's still a problem.

If you haven't looked at the dataset description, you might not know what "Pop2014" or "Property_C" means. I'm going to change the column names so that they make more sense to everyone.

Here's the code for this: image

Inside the .rename method, you can see that I passed in a dictionary. Each key in the dictionary represents the ORIGINAL column name, and each value represents the NEW column name for its corresponding key.

So, in this example, I change "community" to "Neighborhood"; "Pop2014" to "Population in 2014"; and "Property_C" to "Property Crime".

Here's what the dataframe should look like now: image

Displaying the Updated Map WITH THE RENAMED COLUMNS

Now, let's display the map with our updated dataframe:

image

Notice that I said "Property Crime" instead of "Property_C". This is because we changed the column, so "Property_C" no longer exists. If you tried to pass in "Property_C", you would get an error.

image

Looking at the map, all of our 3 columns are changed and that looks really clean!

Video Explanation

Thank you for making it all the way here! I've made a YouTube tutorial that goes over the steps that I talked about in this post. Feel free to check that out here: (insert video)


<
Previous Post
How to Create Interactive Maps in Python
>
Next Post
3 Simple Visuals in Python