'How to create a map in folium using information from two different DataFrames
I would like to create a map using information from two different DataFrames I have already created.
As an example, in the first DataFrame (df_resultados), I have the column ocorrências_match, which has a list of Brazilian cities [tietê, itu, piracicaba etc]. As you can see here:
nome_do_romance autor cidade_natal ano_de_publicação ocorrências ocorrências_match
0 Til José de Alencar Fortaleza - CE 1871 [piracicaba, tietê, atibaia, são paulo, campos... [tietê, itu, piracicaba, mato grosso, são paul...]
In the other DataFrame (df_new), I have the geolocation of those cities in ocorrências_match. As an example:
NOME_MUNICIPIO LONGITUDE LATITUDE
0 alta floresta d'oeste -61.999824 -1.193554
1 ariquemes -63.033269 -9.908463
I would like to iterate through these two DataFrames to match the geolocations of df_new with the cities contained in the ocorrências_match of df_resultados and plot them on a map using folium.
I have already tried some codes, but I can't seem to find a solution. The problem seems to be that I hava many cities in the same row (as a list) in df_resultados.
Solution 1:[1]
Try to explode and merge the dataset, then use it in folium
res = df_resultados.explode("ocorrĂȘncias_match").merge(df_new, how='left', left_on='ocorrĂȘncias_match', right_on='NOME_MUNICIPIO')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | James Flash |
