I want to have a column(Similarity_Index) against each group after group-by using columns s_lat, s_lng, d_lat, d_lng, so that they are identified uniquely. My DataFrame looks like this:
+--------+-------+--------+--------+--------+------------------+------+-------+------+--------------------+-------+---------+
| Id | s_lat | s_lng | d_lat | d_lng | TT | T | Esti2 | Est1 | time_diff | diff | Cluster |
+--------+-------+--------+--------+--------+------------------+------+-------+------+--------------------+-------+---------+
| 67607 | 63.42 | 10.387 | 63.425 | 10.441 | 10.2 | 4.33 | 11 | 4.4 | -0.800000000000001 | -0.07 | 0 |
| 70720 | 63.42 | 10.387 | 63.425 | 10.441 | 9.03333333333333 | 4.36 | 11 | 4.4 | -1.96666666666667 | -0.04 | 0 |
| 68394 | 63.42 | 10.387 | 63.436 | 10.399 | 15.1833333333333 | 2.66 | 10 | 2.7 | 5.18333333333333 | -0.04 | 0 |
| 67340 | 63.42 | 10.387 | 63.436 | 10.399 | 8.91666666666667 | 2.44 | 10 | 2.7 | -1.08333333333333 | -0.26 | 0 |
| 72363 | 63.42 | 10.387 | 63.436 | 10.399 | 9.91666666666667 | 2.47 | 10 | 2.7 | -0.083333333333334 | -0.23 | 0 |
| 70401 | 63.42 | 10.387 | 63.436 | 10.399 | 7.85 | 2.67 | 10 | 2.7 | -2.15 | -0.03 | 0 |
| 70695 | 63.42 | 10.387 | 63.436 | 10.399 | 11.6166666666667 | 3.24 | 10 | 2.7 | 1.61666666666667 | 0.54 | 0 |
| 69698 | 63.42 | 10.387 | 63.436 | 10.399 | 8.91666666666667 | 2.47 | 10 | 2.7 | -1.08333333333333 | -0.23 | 0 |
| 70793 | 63.42 | 10.387 | 63.436 | 10.399 | 11.85 | 2.52 | 10 | 2.7 | 1.85 | -0.18 | 0 |
| 67150 | 63.42 | 10.387 | 63.411 | 10.402 | 4.01666666666667 | 1.68 | 6 | 1.7 | -1.98333333333333 | -0.02 | 0 |
| 69934 | 63.42 | 10.387 | 63.411 | 10.402 | 4.56666666666667 | 1.69 | 6 | 1.7 | -1.43333333333333 | -0.01 | 0 |
+--------+-------+--------+--------+--------+------------------+------+-------+------+--------------------+-------+---------+
s_lat | s_lng | d_lat | d_lng define start and destination lat and lng, I am trying to pair the similar trips based on the locations, what is the best way to achieve it.
Desired Output looks something like this
+--------+-------+--------+--------+--------+------------------+------+-------+------+--------------------+-------+---------+------------------+
| TourId | s_lat | s_lng | d_lat | d_lng | TT | T | Esti2 | Est1 | time_diff | diff | Cluster | Similarity_index |
+--------+-------+--------+--------+--------+------------------+------+-------+------+--------------------+-------+---------+------------------+
| 67607 | 63.42 | 10.387 | 63.425 | 10.441 | 10.2 | 4.33 | 11 | 4.4 | -0.800000000000001 | -0.07 | 0 | A |
| 70720 | 63.42 | 10.387 | 63.425 | 10.441 | 9.03333333333333 | 4.36 | 11 | 4.4 | -1.96666666666667 | -0.04 | 0 | A |
| 68394 | 63.42 | 10.387 | 63.436 | 10.399 | 15.1833333333333 | 2.66 | 10 | 2.7 | 5.18333333333333 | -0.04 | 0 | B |
| 67340 | 63.42 | 10.387 | 63.436 | 10.399 | 8.91666666666667 | 2.44 | 10 | 2.7 | -1.08333333333333 | -0.26 | 0 | B |
| 72363 | 63.42 | 10.387 | 63.436 | 10.399 | 9.91666666666667 | 2.47 | 10 | 2.7 | -0.083333333333334 | -0.23 | 0 | B |
| 70401 | 63.42 | 10.387 | 63.436 | 10.399 | 7.85 | 2.67 | 10 | 2.7 | -2.15 | -0.03 | 0 | B |
| 70695 | 63.42 | 10.387 | 63.436 | 10.399 | 11.6166666666667 | 3.24 | 10 | 2.7 | 1.61666666666667 | 0.54 | 0 | B |
| 69698 | 63.42 | 10.387 | 63.436 | 10.399 | 8.91666666666667 | 2.47 | 10 | 2.7 | -1.08333333333333 | -0.23 | 0 | B |
| 70793 | 63.42 | 10.387 | 63.436 | 10.399 | 11.85 | 2.52 | 10 | 2.7 | 1.85 | -0.18 | 0 | B |
| 67150 | 63.42 | 10.387 | 63.411 | 10.402 | 4.01666666666667 | 1.68 | 6 | 1.7 | -1.98333333333333 | -0.02 | 0 | C |
| 69934 | 63.42 | 10.387 | 63.411 | 10.402 | 4.56666666666667 | 1.69 | 6 | 1.7 | -1.43333333333333 | -0.01 | 0 | C |
+--------+-------+--------+--------+--------+------------------+------+-------+------+--------------------+-------+---------+------------------+