I have a DataFrame of (x, y) coordinates that I would like to transform into array's to perform pairwise distance calculations on.
df = pd.DataFrame({'type': ['a', 'a', 'a', 'b', 'b', 'c', 'c', 'c'],
... 'x': [1, 3, 5, 1, 3, 1, 3, 5],
... 'y': [2, 4, 6, 2, 4, 2, 4, 6]})
Desired output - A new DataFrame of grouped/aggregated coordinates in an array so that I can apply a fuction to each array:
grp = coordinates
a array([[1, 2],
[3, 4],
[5, 6]])
b array([[1, 2],
[3, 4]])
c array([[1, 2],
[3, 4],
[5, 6]])
Distance calculation I wish to apply...
grp['distances'] = grp.apply(lambda x: scipy.spatial.distance.pdist(x['coordinates'], 'euclidean'), axis = 1)
I can't seem to get the groupby function to do this. Any ideas?