I am geocoding a dataset using the column 'Address'. I would like to either add the string 'N/A' to the row 'lat' when an attribute exception is thrown or simply remove that row if the error is thrown.
Here is what I have tried to make the row with the exception say 'N/A':
try:
addresses['lat'] = addresses['Address'].apply(addLat)
addresses['long'] = addresses['Address'].apply(addLong)
except AttributeError:
addresses['lat'] = 'N/A' # this makes every column say N/A
I have also tried:
try:
addresses['lat'] = addresses['Address'].apply(addLat)
addresses['long'] = addresses['Address'].apply(addLong)
except AttributeError:
addresses['lat'] = 'N/A' # this makes every column say N/A
pass # this makes the lat column not exists
but the result of this is having no lat/long columns at all.
My question is, how can I access the specific index of the exception and either ignore or insert 'N/A' during an exception?
I have confirmed that the geocode function works on multiple individual rows of the dataset & am certain that my geocoding function is not the issue.