Trying to do a plot with Folium CircleMaker

395 views Asked by At

I found a very interesting post that I am trying to adapt to my data. Here is the link to the post.

https://alysivji.github.io/getting-started-with-folium.html

Here is the code that I am testing.

import pandas as pd
import gmplot
import matplotlib.pyplot as plt
import folium
from folium import plugins
import seaborn as sns

df = pd.read_csv('C:\\Users\\ryans\\OneDrive\\Desktop\\business.csv')

m = folium.Map([43.7181557,-79.5181415], zoom_start=11)
m

new_df = df[['longitude', 'latitude', 'address']].copy()
new_df.dtypes

# mark each station as a point
for index, row in df.iterrows():
    print(row)
    folium.CircleMarker([new_df['latitude'], new_df['longitude']],
                        radius=15,
                        popup=new_df['address'],
                        fill_color="#3db7e4", # divvy color
                       ).add_to(m)

# convert to (n, 2) nd-array format for heatmap
stationArr = df[['latitude', 'longitude']].to_numpy()

# plot heatmap
m.add_children(plugins.HeatMap(stationArr, radius=15))
m

I'm getting this error.

ValueError: Location should consist of two numerical values, but 0       33.522143
1       43.605499
2       35.092564
3       33.455613
4       35.190012
   
9994    43.629300
9995    36.219236
9996    36.035749
9997    36.148016
9998    43.779707
Name: latitude, Length: 9999, dtype: float64 of type <class 'pandas.core.series.Series'> is not convertible to float.

Here are my data types.

longitude    float64
latitude     float64
address       object

Finally, here is a sample of my new_df.

       longitude   latitude                         address
0    -112.018481  33.522143     2818 E Camino Acequia Drive
1     -79.652289  43.605499            30 Eglinton Avenue W
2     -80.859132  35.092564       10110 Johnston Rd, Ste 15
3    -112.395596  33.455613   15655 W Roosevelt St, Ste 237
4     -80.887223  35.190012  4209 Stuart Andrew Blvd, Ste F
         ...        ...                             ...
9994  -79.625725  43.629300           1135A Crestlawn Drive
9995 -115.278133  36.219236               3240 N Durango Dr
9996 -115.153343  36.035749       7400 Las Vegas Blvd S Ofc
9997 -115.164513  36.148016                2101 Western Ave
9998  -79.418050  43.779707     28 Finch Avenue W, Unit 109

How can I resolve this?

1

There are 1 answers

0
ASH On

After playing with it a bit more, i came up with this.

X = df[['longitude', 'latitude', 'name']].copy()
# mark each station as a point
for index, row in X.iterrows():
    folium.CircleMarker([row['latitude'], row['longitude']],
                        radius=15,
                        popup=row['name'],
                        fill_color="#3db7e4", # divvy color
                       ).add_to(m)

# convert to (n, 2) nd-array format for heatmap
stationArr = df[['latitude', 'longitude']].to_numpy()

# plot heatmap
m.add_child(plugins.HeatMap(stationArr, radius=15))
m

That seems to work fine.

enter image description here

I have never understood these 'fake errors' that are not real errors. Error: can't convert to float. Well, it's already a float, so the machine should not be trying to do some kind of conversion.