Please add a code sample or a nbviewer link, copy-pastable if possible
#!/usr/bin/env python3
import sys
import numpy as np
import pandas as pd
import folium
from folium import plugins
datafile = "/tmp/test.json"
df = pd.read_json(datafile)
stops_map = folium.Map(location=[44.409748, 8.930819], zoom_start=11)
marker_cluster = folium.plugins.MarkerCluster().add_to(stops_map)
counter = 0
for name, row in df.iloc[:].iterrows():
if counter % 10000 == 1:
print(counter, row["latitudine"], row["longitudine"], row["temperatura"])
folium.Marker([row["latitudine"], row["longitudine"]], popup=row["temperatura"]).add_to(marker_cluster)
counter += 1
stops_map.save('/tmp/folium-test.html')
Problem description
I'm quite a python newbie so maybe this could be obvious to most people, but reading a json file (with lot of blanks instead of valid GPS coordinates) and trying to copy from this tutorial leads to a big bold error: RecursionError: maximum recursion depth exceeded in comparison.
I think this is because variables are passed as objects instead of float64 or other base types.
Adding this code after pd.read_json() converts blanks to valid GPS coordinates and downscales variable types to float64 and folium works as expected.
df['longitudine'] = df['longitudine'].replace(r'\s+', np.nan, regex=True)
df['longitudine'] = df['longitudine'].replace(r'^$', np.nan, regex=True)
df['longitudine'] = df['longitudine'].fillna(-0.99999)
df['longitudine'] = pd.to_numeric(df['longitudine'])
df['latitudine'] = df['latitudine'].replace(r'\s+', np.nan, regex=True)
df['latitudine'] = df['latitudine'].replace(r'^$', np.nan, regex=True)
df['latitudine'] = df['latitudine'].fillna(-0.99999)
df['latitudine'] = pd.to_numeric(df['latitudine'])
Sample output can be found here.
Expected Output
No error, or at least a warning such as "Folium can't directly work on object types: pass base types such as float64 or expect problems".
Output of folium.__version__
0.8.3
Please add a code sample or a nbviewer link, copy-pastable if possible
Problem description
I'm quite a python newbie so maybe this could be obvious to most people, but reading a json file (with lot of blanks instead of valid GPS coordinates) and trying to copy from this tutorial leads to a big bold error:
RecursionError: maximum recursion depth exceeded in comparison.I think this is because variables are passed as objects instead of float64 or other base types.
Adding this code after pd.read_json() converts blanks to valid GPS coordinates and downscales variable types to float64 and folium works as expected.
Sample output can be found here.
Expected Output
No error, or at least a warning such as "Folium can't directly work on object types: pass base types such as float64 or expect problems".
Output of
folium.__version__0.8.3