![]() |
Adding markers to Folium map only adding last element. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Adding markers to Folium map only adding last element. (/thread-21827.html) |
Adding markers to Folium map only adding last element. - tantony - Oct-16-2019 I'm finally done with collecting data from FAA website, now I want to add the data to a website using Folium. I'm using the following link for reference. https://python-graph-gallery.com/312-add-markers-on-folium-map/ When I run the script, its only adding the last airport, and I think the problem is because its not adding. When I run my code, I'm getting this below. If you notice, I'm showing 0 for everything. Quote: lat lon name color metar I ran the code from the example above, and I'm getting this below, and its showing all the locations. Quote: lat lon name This is my script. I'm reading a CSV file which contains the name, latitude and longitude of the airports. for row in csvread: icao = row[0] name = row[1] latitude = row[2] longitude = row[3] metar_link = 'https://www.aviationweather.gov/metar/data?ids=' + icao + '&format=decoded&date=&hours=0' page = requests.get(metar_link) soup = bs(page.content, 'html.parser') if soup.select_one('td:contains("Text:") + td').text == 'No data found' or not 'SM' in ( soup.select_one('td:contains("Text:") + td').text): continue metar = soup.select_one('td:contains("Text:") + td').text metar_data = func.fraction(metar) visibility = float(func.convert_to_float(metar_data)) ceiling = func.convert_ceiling(metar) flight_conditions = func.flight_conditions(ceiling, visibility) color = func.colorize(flight_conditions) data = pd.DataFrame({ 'lat': [latitude], 'lon': [longitude], 'name': [name], 'color': [color], 'metar': [metar] }) print(data) metar_map = folium.Map(location=[50.4512, -104.6166], tiles='cartodbpositron', zoom_start=4) for i in range(0, len(data)): folium.CircleMarker(location=[data.iloc[i]['lat'], data.iloc[i]['lon']], radius=5, color=data.iloc[i]['color'], fill=True, fill_color=data.iloc[i]['color'], tooltip=([data.iloc[i]['name']]+[data.iloc[i]['metar']])).add_to(metar_map) metar_map.save('metars_map.html') |