Give a data frame like below:
| index | H_Lat | H_Lon | W_Lat | W_Lon |
|---|---|---|---|---|
| 0 | 18.447259 | 73.896742 | 18.534579 | 73.819043 |
| 1 | 18.523069 | 73.842460 | 18.491357 | 73.851985 |
| 2 | 18.511014 | 73.864071 | NaN | NaN |
I want a new column added that calculates the distance between the two places (H_Lat, H_Lon) and (W_Lat, W_Lon)
| index | H_Lat | H_Lon | W_Lat | W_Lon | Distance |
|---|---|---|---|---|---|
| 0 | 18.447259 | 73.896742 | 18.534579 | 73.819043 | 12.678631 |
| 1 | 18.523069 | 73.842460 | 18.491357 | 73.851985 | 3.651333 |
| 2 | 18.511014 | 73.864071 | NaN | NaN | NaN |
I followed Getting distance between two points based on latitude/longitude answer to calculate the distance between two coordinates.
But I am not sure how to add a new column to the data frame for each row.
Define a function that calculates the distance:
The following code will add a new column 'distance' to the data frame: