Unable to visualize geographic data due to error

Screen Link:
https://app.dataquest.io/m/150/visualizing-geographic-data/10/displaying-great-circles

My Code:

fig, ax = plt.subplots(figsize=(15,20))
m = Basemap(projection='merc', llcrnrlat=-80, urcrnrlat=80, llcrnrlon=-180, urcrnrlon=180)
m.drawcoastlines()

# Start writing your solution below this line

def create_great_circles(the_dataframe):
    
    for index, each_route in the_dataframe.iterrows():
        if ((abs(each_route.iloc[4] - each_route.iloc[5]) < 180) & (abs(each_route.iloc[6] - each_route.iloc[7]) < 180)):
            m.drawgreatcircle(each_route.iloc[4], each_route.iloc[5], each_route.iloc[6], each_route.iloc[7])
            
dfw = geo_routes[geo_routes["source"] == "DFW"]
create_great_circles(dfw)
plt.show()

What I expected to happen:
I was expecting a map to be generated with the routes

What actually happened:

ValueError: cannot convert float NaN to integer

I’m not sure why this error keeps coming up. I’ve checked and rechecked the data for any NaN values for the Source column with the value DFW. I also ran the dropna() function against the dataframe and that did not help either.
I searched for this error but all I’ve understood is that its for NaN values. However considering I have none, I’m stuck :hot_face:
Any help would be appreciated

hey @jesmaxavier

this line is the trouble maker here!

the sequence m.drawgreatcircle expects is (lon, lat, lon, lat), you have provided it with (lon, lon, lat, lat).

you have enough hints to try now. still want to cheat on it let us know! will give you a prompt solution and negative marking! :smiley: kidding…

@Rucha thank you!! :slightly_smiling_face: I guess I was a bit excited and overconfident that I failed to see the detail.

Though I’m curious of the error message itself. It makes no sense when you compare it to what caused the error. Do you have any idea how they are related? :thinking:

@jesmaxavier

I understand your curiosity on the error front, but sorry I won’t be able to help you, for this case at least. The reason being for this particular instruction, I cross-checked your code with my own to see the difference and caught the misplaced columns.

this is where drawgreatcircle method was born - https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/init.py
(For me, this is like watching Inception without even knowing all the planets. Poor Pluto considered!)

apologize for my previous post if you have already read it. went too explanatory :frowning:

@bruno/ @josh/ @hanqi / @juliechipko any inputs? this is the error that is received.

/dataquest/system/env/python3/lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py in drawgreatcircle(self, lon1, lat1, lon2, lat2, del_s, **kwargs)
   2882         gc = pyproj.Geod(a=self.rmajor,b=self.rminor)
   2883         az12,az21,dist = gc.inv(lon1,lat1,lon2,lat2)
-> 2884         npoints = int((dist+0.5*1000.*del_s)/(1000.*del_s))
   2885         lonlats = gc.npts(lon1,lat1,lon2,lat2,npoints)
   2886         lons = [lon1]; lats = [lat1]

ValueError: cannot convert float NaN to integer

Its all good. You went the extra mile, no harm done. Thank you.

BTW did you mean Interstellar? Inception does not have planets… :slightly_smiling_face:

hey @jesmaxavier

well, that sums up my qualification. I must be :sleeping: while posting that! yeah, Interstellar! Seriously :woman_facepalming: !