HTML page is blank after using folium to create map

3.1k views Asked by At

I was wondering if anyone would be able to help me in fixing my Python/HTML code. I am trying to plot the locations of volcanoes near Lake Shasta using the folium library in Python and pandas to zip the latitude, longitude, name, and elevation columns from a CSV file. The CSV file is properly formatted as I can access the data (e.g. calculate means). While I managed to create a dataframe, my print out of the HTML code does not yield the desired map. I am using chrome to try and open the file. Below is the code. Any help in resolving the issue would be greatly appreciated! Thanks in advance!

Kyle

import folium
import pandas as pd

df = pd.read_csv('Volcanoes_USA.csv')
latmean = df['LAT'].mean()
lonmean = df['LON'].mean()

map = folium.Map(location = [latmean, lonmean], zoom_start = 5, tiles = 'Stamen Terrain')

def color(ELEV):
    if ELEV in range(0, 1000):
        col = 'green'
    elif ELEV in range (1001,1999):
        col = 'blue' 
    elif ELEV in range(2000,2999):
        col = 'orange'
    else:
        col = 'red'

for LAT,LON,NAME,ELEV in zip(df['LAT'], df['LON'], df['NAME'], df['ELEV']):
    folium.Marker(location=[LAT, LON], popup = NAME, icon = folium.Icon(color = color(ELEV), icon = 'cloud')).add_to(map)

print(map.save("test6.html"))
1

There are 1 answers

0
Tokaalmighty On

If there are quotes (') in the string, you will get a blank page.

You need to make the following change:

popup=folium.Popup(df['NAME'],parse_html=True))