Apr-07-2020, 05:17 AM
Hi,
I am getting -ValueError: could not convert string to float while trying to generate a map via geographical coordinates. My code is below:
I gathered coordinates of various location in a city according to below code.
My data set image is attached for reference.
Regards,
Rahul
I am getting -ValueError: could not convert string to float while trying to generate a map via geographical coordinates. My code is below:
I gathered coordinates of various location in a city according to below code.
My data set image is attached for reference.
location = [x for x in rest_df['Restaurant_Location'].unique().tolist() if type(x) == str] latitude = [] longitude = [] for i in range(0, len(location)): if(type(location[i]) == str): ctr=0 while True: try: address = location[i] + ', Mumbai, India' geolocator = Nominatim(user_agent="ny_explorer") loc = geolocator.geocode(address) latitude.append(loc.latitude) longitude.append(loc.longitude) print('The geograpical coordinate of location are {}, {}.'.format(loc.latitude, loc.longitude)) except: ctr+=1 if(ctr==7): print(i) latitude.append(address) longitude.append(address) break continue break
rest_df['location_latitude'] = rest_df['Restaurant_Location'].map(dict(zip(location, latitude))) rest_df['location_longitude'] = rest_df['Restaurant_Location'].map(dict(zip(location, longitude))) dataframe_filtered = rest_df.groupby(['Restaurant_Location'])['location_latitude', 'location_longitude'].first() dataframe_filtered['no_restaurant'] = rest_df.groupby(['Restaurant_Location'])['Cost_for_two'].count() venues_map = folium.Map(location=[19.076090, 72.877426], zoom_start=11) states = folium.map.FeatureGroup() i=0 for lat, lng, in zip(dataframe_filtered.location_latitude, dataframe_filtered.location_longitude): states.add_child( folium.CircleMarker( [float(lat), float(lng)], radius=5, # define how big you want the circle markers to be color='yellow', fill=True, fill_color='blue', fill_opacity=0.6, ) ) i+=1 i=0 for lat, lng, in zip(dataframe_filtered.location_latitude, dataframe_filtered.location_longitude): states.add_child( folium.Marker( [float(lat), float(lng)], popup= dataframe_filtered.index[i], ) ) i+=1 # add incidents to map venues_map.add_child(states) venues_mapThe error which I am getting is below:
Error:C:\Users\Klsingh\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: FutureWarning:
Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-57-de12d43743bd> in <module>
8 states.add_child(
9 folium.CircleMarker(
---> 10 [float(lat), float(lng)],
11 radius=5, # define how big you want the circle markers to be
12 color='yellow',
ValueError: could not convert string to float: 'Dadar Shivaji Park, Mumbai, India'
Please help. Thank you.Regards,
Rahul