Search code examples
pythonpandaslambdageopy

Save Lambda's Progress if something went wrong


I'm trying to use geopy on a list of addresses with pandas and lambda, but if connection is lost I'll lose all the progress, is there a way to somehow save it so if something went wrong in the middle of the procedure I can just continue from where I've stopped? that's the line I'm using, it's a very basic line

df.output = df.Address.apply(lambda x: geolocator.geocode(x,timeout=30,language="en")).apply(lambda x: x.raw))

Solution

  • Give this a try. There's plenty of examples for iterrows, iteritems, itertuples. Without knowing the goelocator function or how it works, you may have to tweak this.

    for index, row in df.iterrows():
        gcode = geolocator.geocode(row['Address'],timeout=30,language="en")
        row['output'] = gcode.raw