Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
lorienb
New Member

Using geopandas to interact with polygons on a map

 

Hello, my end goal is to create a Power BI page with two components: a table and a map.

  • The table will contain data for a given region on the map.
  • The map will be interactive so that when users click on a region of the map, the table is updated with data from that region. 

Here is a box link to the shapefile I am working with.

 

Right now, I am trying to use geopandas (the python library) to plot the region polygons on a map in Power BI with the Python visual tool, but I can't get any polygons to be displayed. Here are the steps I have taken:

1. I imported the data using the Python script tool:

 

 

import geopandas as gpd ​
from shapely import wkt ​
region_polygons = gpd.read_file("insert_local_file_path_here") ​
region_polygons = pd.DataFrame(region_polygons)

 

 

(I had to convert it from a geodataframe to a dataframe since Power BI wouldn't recognize anything to import unless it was in the form of a pandas dataframe).

 

2. I created a python visual and dragged my 'geometry' column onto that visual. I then wrote the following script to convert the dataframe to a geodataframe and plot it in on the page using .plot():

 

 

import geopandas as gpd​
gdf = gpd.GeoDataFrame(dataset, geometry='geometry')​
gdf.plot()

 

 

The visual then displays a message saying "Can't display this visual" and when I click to see details, I get a type error stating that my 'input must be valid geometry objects':

error_1.png

 

 

3. Through some troubleshooting, I've determined that it's the second line throwing the error, when I attempt to create a geodataframe from the dataframe that holds my geometry data. It is expecting geometry objects such as Shapely polygons, but the geometry column is stored as text in Power BI. I verified this by inspecting its data type in Power BI:

data_types.png

 

4. ​I found this StackOverflow thread and tried to convert the geometry column to Shapely polygons, but immediately encountered an error:

 

 

import geopandas as gpd​
from shapely import wkt​
# convert dataset column from well-known text type (string) to shapely polygons​
dataset['geometry'] = gpd.GeoSeries.from_wkt(dataset['geometry'])

 

 

error_2.png

 

I am finding it almost impossible to troubleshoot further as I can't find a way to output variables to a console in Power BI and because I can't reproduce the problem in my Jupyter Python environment. Is it possible to convert data to data types that geopandas requires, such as Shapely polygons and geometry columns? Is geopandas compatible at all with Power BI for this type of work? If anyone has any ideas please let me know. Thanks in advance.

 

For context, only four lines of code are necessary in my Jupyter Python environment to display these polygons. This works:

 

 

import geopandas as gpd ​
file_path = "insert_local_file_path_here" ​
region_polygons = gpd.read_file(file_path) ​
region_polygons.plot()

 

 

And produces this plot:

successful_plot.png

1 REPLY 1
lbendlin
Super User
Super User

You must use the standard plotting engine. Only matplotlib is supported. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.