Closed pleabargain closed 8 years ago
Relevant: https://github.com/pbugnion/gmaps/issues/68#issuecomment-230229399
Basically data needs to be like: [(lat,lon),(lat,lon)]
, so an iterable of tuples.
You could transform:
array([[ nan, nan],
[ 38., 0.],
[ 45., 0.]]))
which I read as a np.array of np.arrays of size 2 (Nx2 matrix) by going:
data=[(d[0],d[1]) for d in data]
@reyale Thank you. I tried variations on your suggestion
mydata = np.genfromtxt("/home/dgd/Desktop/text.csv", delimiter=',')
data = mydata
data =[(d[0],d[1]) for d in data]
heatmap_layer = gmaps.Heatmap(data=data)
m.add_layer(heatmap_layer)
m
but got InvalidPointException: (nan, nan) is not a valid latitude, longitude pair
I'm grateful for any other tips you might have to resolve my goal with gmaps.
thank you Dennis
Dennis,
My guess is that you have a blank or invalid float value in your csv, and that np.genfromtxt fills these values with np.nan. Please verify all data is not nan.
You might try:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html
missing_values : variable, optional The set of strings corresponding to missing data. filling_values : variable, optional The set of values to be used as default when the data are missing.
in np.genfromtxt
to automatically fill these values with valid floats.
@pleabargain If you can attach the CSV to the issue (or any subset of the CSV that causes the error), we may be able to give more targeted answers.
If you do have nan
values in your data, you will have to remove these as a pre-processing step beforehand.
PRs for improved error handling always welcome!
Closing as likely not a problem in gmaps directly. That said, we should improve the way we notify the user that their data is invalid.
gmap notebook.ipynb.zip Hello
I have attached the ipynb file that I used while working on this problem. I removed the API key.
goal: load simple local csv files directly.
I have tried many options(see below). What code would you recommend I use to get a local csv to load properly?
thank you Dennis
error
ValueError: could not convert string to float: b'lat'
error:
ValueError: could not convert string to float: b'lat'
error: TraitError: The 'data' trait of a Heatmap instance must be a list, but a value of class 'numpy.ndarray' (i.e. array([[ nan, nan], [ 38., 0.], [ 45., 0.]])) was specified.
error:
TraitError: The 'data' trait of a Heatmap instance must be a list, but a value of class 'map' (i.e. <map object at 0x7fa4ac122320>) was specified.