python - Pythonic way to get closest point for each point in a data frame (Nearest Neighbour) -


I have a list of places and towers I am trying to figure out, for each location, what is the nearest tower I work in a way that works, but I am pretty sure that it is a very inefficient way of doing it.

How do I do this more dragonically?

I have over 4,000 locations and 11,000 towers

  • to find the distance to the towers
  • sorting Distance
  • I am currently:
    1. From the closest to the nearest 'tower' data frame reaching the frame.

      Here's the code:

        Nikttmtm = pd.DataFrame () for I, ( "Late", "Long"]] in Sthan_rojh: Tovr_kold [ "Duri_kmi"] = Tovr_clons.apli (lambda row: Duri_on_anit_sferr (Sthan_sresht [ "kick"], Sthan_ro [ "Long"], row [ 'DIGITAL_LATITUDE'], row [ 'DIGITAL_LONGITUDE']) * 6373, axis = 1) a = tower_coords.sort ([Distance_km '], ascending = 1) [: 1] [[ "SITE_NUMBER [" service _ Long "] [location =" ""] "Sthan_kang", "Sthan_kam"] = "position _ name "Long"] Nearest = The closest powder. Append (A) Print (i)   

      Tovr_kold looks like this:

        SITE_NUMBER DIGITAL_LATITUDE DIGITAL_LONGITUDE 1 67.21 -30.432 ..    

      < First, use min () to find the closest find you provide a key after the repetition of arguments = "text =" post-text "itemprop =" text ">

      can (which will be your lambda function).

      it would be more dragon to use a class instead of like structure instead of hash your a object of the PAP's implementation hash Like reach With the use of square properties are more efficient.

      This entire work can be done in a map operation. You are taking a structure and mapping the elements between 1-1 correspondence in any other structure, which makes it a map .

      In the end (and it's not about being phenolic but it's important), you should use a structure to find the nearest point.

  • Comments

    Popular posts from this blog

    c - Mpirun hangs when mpi send and recieve is put in a loop -

    python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

    java - Unable to get JDBC connection in Spring application to MySQL -