Python - Appending a new Dataframe column that is a function of two separate numerical columns
Use the distance matrix to know the distance from one point to all other corresponding points.

Here is an example:

def dist_PQ(P,Q):
    PP=P*P
    QQ=Q*Q
    PSquared_Sum = np.sum(PP,axis=1,keepdims=True)
    QSquared_Sum = np.sum(QQ,axis=1,keepdims=True)

    squared_distance = PSquared_Sum + QSquared_Sum.T - 2*np.dot(P,Q.T)

    return(squared_distance)



Use the above function to find distances between two sets of points say (P and Q)
Say P has 10 points the values are as numpy array [[x11,y11],[x12,y12],[x13,y13]...] and Q has 3 points as [[x21,y21],[x22,y22],[x23,y23]].
pass P and Q to the dist_PR function to get the output as (10,3) matrix which gives the distances from all points in array P to all points of Q.


Now we can use the matrix of distance in our further calculation.
Suppose we want to find the place which is nearest from P1 (a point in P), we can simply find the minimum distance value in row number 1 of that distance matrix.