0

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.

1 Answers1

0

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')
James Flash
  • 528
  • 7
  • 15
  • James Flash, I think you haven't considered or I have not made it clear that in the rows of df_resultados, we have a list of cities. Don't we have to itarate through it? – Digital_humanities May 24 '22 at 12:20
  • I think you haven't considered or I have not made it clear that in the rows of df_resultados, we have a list of cities. Don't we have to itarate through it? – Digital_humanities May 24 '22 at 12:25
  • After building `res` dataframe you don't have the list of cities (due to `explode` method) but you may have some duplicated rows. Then you can plot all cities in the same way like in [this post](https://stackoverflow.com/questions/39401729/plot-latitude-longitude-points-from-dataframe-on-folium-map-ipython) – James Flash May 24 '22 at 12:38