title: Create groups which distance is =< n km from a matrix distance in python
body: <p>I created a matrix distance in python. What I am trying to do is group by distance each point with a criteria value of &lt;500 (km) and then obtain what is the name of this city and got it as a new data frame following my next code:</p>
  <pre><code>    from sklearn.neighbors import DistanceMetric
      import pandas as pd
      import numpy as np
      #coordinates to radians 
      df['Lat'] = np.radians(df['Lat'])
      df['Long'] = np.radians(df['Long'])
      df_radians = df.loc[:, ['Lat', 'Long']]
      dist = DistanceMetric.get_metric('haversine')
      #Get only values &lt; 500 to group
      boolean=pd.DataFrame(dist.pairwise(data[['Lat','Long']].to_numpy())*6373,
       columns=df.city_name.unique(), index=df.city_name.unique()) &lt;500
      #Finding indices from each point to other points for which the minium distance is satisfied
      matrix = [[] for n in range(len(boolean))] for row_i, row in enumerate(boolean):
        matrix[row_i] = list([i for i, is_true in enumerate(row) if is_true])
     
  </code></pre>
  <p>The result is <code>[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],...]</code> and I know that this index has a label name (city_name) and I want return this values as:</p>
  <pre><code>city_name Group
  Miambar   1
  Nairobi   1
  Kuhlestan 1
  Paris     2
  Lyon      2
  Miami     3
  Orlando   3   
  </code></pre>