I am attempting to map a bunch of points from a .csv file within Jupyter Notebook using folium. Within my dataframe I have two columns named "Latitude" and "Longitude" which hold coordinate information as floats.
Here is the code I am using: **EDIT TO INCLUDE DATAFRAME CODE
import folium
from folium.plugins import FastMarkerCluster
%matplotlib inline
import pandas as pd
import re
import os
import branca.colormap as cm
import re
import numpy as np
df = pd.read_csv('D:/documents/professional/school/hunter/data/Retail_Food_Stores.csv')
print(folium.__version__)
Import .csv and modules
def createLatLong(location):
try:
return re.findall(r'\((.*?)\)', location)
except:
return None
def createLatLongColsX(item):
for items in df_nyc['Lat_Long']:
for item in items:
try:
return re.split(',', item)[0]
except:
return None
def createLatLongColsY(item):
for items in df_nyc['Lat_Long']:
for item in items:
try:
return re.split(',', item)[1]
except:
return None
df_nyc['Latitude'] = df_nyc['Location'].apply(createLatLongColsX)
df_nyc['Longitude'] = df_nyc['Location'].apply(createLatLongColsY)
df_nyc['Latitude'] = df_nyc['Latitude'].astype(float).fillna(0.0)
df_nyc['Longitude'] = df_nyc['Longitude'].astype(float).fillna(0.0)
Create columns holding point values
this_map = folium.Map(prefer_canvas=True)
def plotDot(point):
try:
folium.CircleMarker(location=[point.Latitude, point.Longitude],
radius=2,
weight=10,#remove outline
popup = point['Entity Name'],
fill_color='#000000').add_to(this_map)
except:
break
df.apply(plotDot, axis = 1, raw=True)
this_map.fit_bounds(this_map.get_bounds())
this_map
Create map and apply to dataframe rows
Fortunately, the map does display somewhat correctly in that it is appearing within the notebook. However, the point which appears is always the same regardless of how I slice the dataframe. Interestingly the name displayed in the popup when the point is clicked is always the last item name in the sliced portion of my dataframe.
So, it seems like it's pulling in the name correctly, but not populating the marker locations correctly. Using Python 2.7 within the notebook.
EDIT 2 -
Est_Type_Long Latitude Longitude
0 [Multiple Operations, Store, Food Manufacturer] 40.676932 -73.969136
1 [Multiple Operations, Store, Food Manufacturer] 40.676932 -73.969136
2 [Multiple Operations, Store, Food Manufacturer] 40.676932 -73.969136
3 [Multiple Operations, Store, Bakery, Food Manu... 40.676932 -73.969136
4 [Multiple Operations, Store, Food Manufacturer] 40.676932 -73.969136