How to insert an html table as a python variable into Folium map

Viewed 189

I'm trying to insert an html table as a Folium popup. However I can't.

Here is what I'm trying to do:

# I import an excel table as a pandas df:
df_1 = pandas.read_excel('prisioners.xlsx')

# I crete an empty folium map:
m = folium.folium.Map(location=[df_1['latitude'].mean(), df_1['longitude'].mean()], tiles='OpenStreetMap', zoom_start=8,crs='EPSG3857')

# I create a featuregroup to use as a layer in my map:
fg_11 = folium.map.FeatureGroup(name='1.1 Roubo').add_to(m)

# I extract just one column of my DF to use in my map:
df_11 = df_1[df_1['tipologia'] == 'Roubo']

# I create a function to use the variables inside a html table in my map:
def popup_html_11(row):
    foto = df_11['picpath'].iloc[row]
    nome = df_11['nome'].iloc[row]
    entrada = df_11['entrada'].iloc[row]
    saida = df_11['saída'].iloc[row]
    status = df_11['status'].iloc[row]
    nascimento = df_11['nascimento'].iloc[row]
    rg = df_11['rg'].iloc[row]
    cpf = df_11['cpf'].iloc[row]
    raca = df_11['raça'].iloc[row]
    naturalidade = df_11['naturalidade'].iloc[row]
    mae = df_11['mãe'].iloc[row]
    pai = df_11['pai'].iloc[row]
    rua = df_11['rua'].iloc[row]
    numero = df_11['número'].iloc[row]
    bairro = df_11['bairro'].iloc[row]
    cidade = df_11['cidade'].iloc[row]
    estado = df_11['estado'].iloc[row]
    unidade = df_11['unidade'].iloc[row]
    tipologia = df_11['tipologia'].iloc[row]
    left_col_color = "#EF5350"
    right_col_color = "#EF9A9A"
    html =  # that's my question below: I don't want to write the html table here, but in another archive inside my projet in pycharm. How can I do that?
    return html

# Finally, I iterate everything in my map to create markers and use a the previous html table as popups in my map.
for row in range(0, len(df_11)):
    df_11.iloc[row]
    html_11 = popup_html_11(row)
    popup_11 = folium.Popup(html_11)
    location_11 = [df_11['latitude'].iloc[row], df_11['longitude'].iloc[row]]
    cor_11 = 'red'
    icon_11 = folium.Icon(color=cor_11, icon='user', prefix='glyphicon')
    marcadores_11 = folium.map.Marker(location=location_11, popup=popup_11, icon=icon_11).add_to(m)
    fg_11.add_child(marcadores_11)

Question: as I wrote above, I don't want to write the html table here, but in another archive inside my projet in pycharm. How can I do that? how can call inside my html variable my html archive?

Thanks

0 Answers
Related