-2

Here is the code:

    import folium
    import pandas as pd
    
        corona_map = pd.read_csv('https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_d

ata/csse_covid_19_daily_reports/07-07-2020.csv')
    corona_map.head()
    worldMap = folium.Map(location = [ 31.7917 , -7.0926 ], tiles = 'cartodbpositron', zoom_start = 6)
    folium.Circle(location = [ 31.7917 , -7.0926 ], radius = 100*1000, color = 'yellow', fill = True, popup='Confirmed: {}'.format(20)).add_to(worldMap)

    def map_marker(x):
      folium.Circle(location= [x[0], x[1]],
      radius = float(x[2])*10, 
      popup = 'Confirmed: {}'.format(x[3])).add_to(worldMap)

    corona_map[['Lat', 'Long_', 'Confirmed', 'Combined_Key']].apply(lambda x: map_marker(x), axis  = 1)

the Error:

ValueError                                Traceback (most recent call last)
<ipython-input-146-36a6b307c9ea> in <module>()
     10   radius = float(x[2])*10,
     11   popup = 'Confirmed: {}'.format(x[3])).add_to(worldMap)
---> 12 corona_map[['Lat', 'Long_', 'Confirmed', 'Combined_Key']].apply(lambda x: map_marker(x), axis  = 1)

7 frames
pandas/_libs/reduction.pyx in pandas._libs.reduction.compute_reduction()

pandas/_libs/reduction.pyx in pandas._libs.reduction.Reducer.get_result()

/usr/local/lib/python3.6/dist-packages/folium/utilities.py in _validate_coordinates(coordinates)
     53     if _isnan(coordinates):
     54         raise ValueError('Location values cannot contain NaNs, '
---> 55                          'got:\n{!r}'.format(coordinates))
     56     coordinates = _iter_tolist(coordinates)
     57     return coordinates

ValueError: Location values cannot contain NaNs, got:
[nan, nan]

when I execute the last line of code it gives me this error, I searched on stackoverflow but couldn't fix it,

thank you everyone.

Prooosma
  • 21
  • 6
  • if error shows that it get `[nan, nan]` then use `print()` to see values in all variable until you find `nan`. First check `print(x)` inside `map_marker` – furas Jul 08 '20 at 10:33
  • I know the values that are NAN but I can't change them since they are in web url. – Prooosma Jul 08 '20 at 10:37
  • then use `If/else` in `map_marker` to skip this element, or to use some default value or random value or mean value. OR maybe you should first clear data in table and put some values in place of `nan` or filter them before displaying. – furas Jul 08 '20 at 10:50

1 Answers1

1

I found the solution, I just added these two line from this question: Removing NaN Values from csv

here is the two lines:

corona_map = corona_map.replace('',np.nan)
corona_map = corona_map.dropna(axis="rows", how="any")

I added them before the last line in the code.

Prooosma
  • 21
  • 6