I came across this SQL problem and wonder if I could solve it in python pandas.
The SQL problem: Table point holds the x coordinate of some points on x-axis in a plane, which are all integers.
Write a query to find the shortest distance between two points in these points.
| x |
|-----|
| -1 |
| 0 |
| 2 |
I have initiate the pandas dataframe as below.
import pandas as pd
point = pd.DataFrame(np.array([-1,0,2]), columns=['x'])
I was trying to do like
p1 = point
p2 = point.copy()
p1.merge(p2, on='x', condition = ('!='))
But I know there is no such conditions.
Can anyone provide a solution to this problem in pandas?
Note: My problem is different from join two dt when columns are not equal, so it is not a duplicate. My problem is about appending all values to each of the values in the original set. The problem in the link is about finding out the difference.