When trying to convert zip codes to state in a dataframe Code :
from pyzipcode import ZipCodeDatabase
zcdb = ZipCodeDatabase()
df4[‘state’] = df4[‘postal_code’].map(lambda x: zcdb[x].state)
Throws an error
“Couldnt find zipcode : ‘39826’”
Need to ignore this error and move on to the next row
There are multiple ways. The older pattern is
try/except.The more modern pattern is to use
contextlib.suppressThere's also a slightly hacky way, looking the
pyzipcodesource: