AlejandroDGR
AlejandroDGR

Reputation: 188

Geodataframe.explore() error: __init__() missing 1 required positional argument: 'location'

I'm trying to plot an interactive map using Geopandas and its explore() method in Colab.

However, when I write:

my_geodataframe.explore()

The following error arises:

TypeError                                 Traceback (most recent call last)
<ipython-input-11-e71fb33b059f> in <module>()
----> 1 mapa_interactivo = mapa1.explore()

1 frames
/usr/local/lib/python3.7/dist-packages/geopandas/explore.py in _explore(df, column, cmap, color, m, tiles, attr, tooltip, popup, highlight, categorical, legend, scheme, k, vmin, vmax, width, height, categories, classification_kwds, control_scale, marker_type, marker_kwds, style_kwds, highlight_kwds, missing_kwds, tooltip_kwds, popup_kwds, legend_kwds, **kwargs)
    511             marker_kwds["radius"] = marker_kwds.get("radius", 2)
    512             marker_kwds["fill"] = marker_kwds.get("fill", True)
--> 513             marker = folium.CircleMarker(**marker_kwds)
    514         else:
    515             raise ValueError(

TypeError: __init__() missing 1 required positional argument: 'location'

I explicitly write the location:

my_geodataframe.explore(location=[40.463667, -3.74922])

But the error remains.

I'm creating maps which show the unemployment rate per province in Spain. The geodata can be downloaded from the following source:

http://centrodedescargas.cnig.es/CentroDescargas/buscar.do?filtro.codFamilia=LILIM&filtro.codCA=11#

And the unemployment rate data per province may be downloaded from this one:

https://www.ine.es/jaxiT3/Datos.htm?t=3996

After merging the information into a unique geodataframe, I get something like this:

Provincia Codigo Tasa_Paro geometry
València/Valencia 46 14.75 MULTIPOLYGON (((-1.20715 40.00183, -1.21662 40...
Toledo 45 16.77 POLYGON ((-5.40611 39.87773, -5.40618 39.87884...
Teruel 44 10.60 POLYGON ((0.14136 40.71821, 0.12382 40.72081, ...
Tarragona 43 15.51 MULTIPOLYGON (((0.70759 40.63522, 0.70732 40.6...
Soria 42 9.73 POLYGON ((-1.99369 41.57709, -1.99311 41.57646...

I've been able to plot a static choropleth map with no problem:

Unemployment rate per province. Spain. 2021T1

You can find the code I've used to plot it in the following link:

https://github.com/AlejandroDGR/Proyecto_Difusion_Universitarios_INE/blob/master/Casos_de_uso_Python/C%C3%B3mo%20dibujar%20mapas%20est%C3%A1ticos%20en%20Python.ipynb

The problem, as stated above, comes with trying to plot an interactive map.

Any recommendations?

Upvotes: 2

Views: 877

Answers (2)

martinfleis
martinfleis

Reputation: 7814

The code above is correct. The issue is that you are using the old, unsupported version of folium. GeoPandas explore has been designed to work with folium 0.12 and newer, you need to update.

Upvotes: 1

Michael Delgado
Michael Delgado

Reputation: 15452

The first positional argument to geopandas.GeoDataFrame.explore is column:

column: str, np.array, pd.Series (default None)
The name of the dataframe column, numpy.array, or pandas.Series to be plotted. If numpy.array or pandas.Series are used then it must have same length as dataframe.

If you're plotting a dataframe with more than one column, be sure to provide the name of the column you would like to explore, as in:

my_geodataframe.explore('Tasa_Paro')

Upvotes: 2

Related Questions