Python Beginner here. I have a python dataframe consisting of X,Y points that looks similar to this:
What I want to do is look at row 1 and find the distance between row 1 and row 2 and output the new distance between those 2 X,Y locations to a new column called "dist". Then do the same for row 2 and 3 and so on. My X,Y data is much larger than this, but this is the basis for my problem. Ultimately the data stops, each point is making up a larger polyline so the end point will have a zero distance.
I'm aware I can use geopy, numpy, and pyproj as few. I initially tried haversine distance but was having issues importing the python module. I'm not sure how to approach this problem using those modules, do I need a search cursor and apply that to each row? So, If I have a polyline with nodes, calculating the distances between each of those nodes. These are coordinates in real locations on earth, so not a cartesian coordinate system, if you will

In order to calculate distances between following points you can use an approach below. For the testing purposes I defined corners of a rectangle.
this gives a pandas Series with the following values:
[nan, 1.0, 1.0, 1.0, 1.0]So now you can drop lag columns with
df.drop(["X_lag", "Y_lag"], axis=1, inplace=True)and you get:For a geographic distance you can
import geopy.distanceand apply the following code. It will interpret previous numbers as degrees.Which give distance in meters:
[nan, 110574.3885578, 111302.64933943, 110574.3885578, 111319.49079327, 156899.56829134]