Getting different output for DataFrame & normal implementation of same code

66 Views Asked by At

I'm trying to calculate vincety distance between two points of a DataFrame. If I input strings directly I get following output:

loca1 = [12.9404578177, 77.5548244743]
loca2 = [12.9404578177, 77.5548244743]
print vincenty(loca1,loca2).meters 

>>>0.0

While implementing same thing with Dataframe I get following output:

from geopy.distance import vincenty 
for i in range(len(cleandata)):
    if i < 303708:
        location2 = cleandata.iloc[i]['location']
        location1 = cleandata.iloc[i+1]['location']
        cleandata.iloc[i]['distance'] = vincenty(location1, location2).meters
    else:
        print i

print cleandata.loc[1]['distance']
>>>*13921

cleandata['location'] has exactly the same coordinates strings I put in 1st code. I checked in both cases the variables going into vincety function are lists.

How to explain and fix this strange behaviour?

1

There are 1 best solutions below

0
On

Well I got my answer, the values 13921 was from previous code which was not getting over written, following change made the overwriting possible

cleandata.iloc[i,'distance'] = vincenty(location1, location2).meters

instead of cleandata.iloc[i]['distance']