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

Time:02-26

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:

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ómo dibujar mapas estáticos en Python.ipynb

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

Any recommendations?

CodePudding user response:

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')

CodePudding user response:

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.

  • Related