Skip to content
Advertisement

How find the distance in meters between two points in a dataframe?

I have a dataframe where, columns with subscript 1 are starting points and with 2 are end points. I want to find a difference in kilometers between them. I tried following code however got an error

JavaScript

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Advertisement

Answer

Try using .apply() with lambda function so that you can pass the coordinates as scalar values instead of now passing 4 Pandas series to the function:

JavaScript

You can also use list(map(...)) for faster execution, as follows:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement