I need to add field to my DataFrame with calculated distance between Location A and Location B. I have this code which works fine for fields with not empty coordinates:
df['Distance_AB'] = df.apply(lambda x: great_circle((x['latitude_A'],x['longitude_A']), (x['latitude_B'], x['longitude_B'])).meters, axis=1).round()
But when it encounters empty field it throws an error:
ValueError: ('Point coordinates must be finite. (nan, nan, 0.0) has been passed as coordinates.', u'occurred at index 2881')
How can ensure that formula for great circle distance will not receive NULL value (distance calculation will be skipped when no coordinates are available)? I am aware of pd.notnull()
function but it returns True
or False
.