-1

I have trouble with my project to make a recommendation list for landmarks. So I have a database like a graph below and I iterate function over. What I don't understand is how to perform an iteration over function from an input (sys.arg(v)) into the data frame??. Thanks for the answer.

The Function :

def haversine(lon1,lat1,lon2,lat2):
    lon1, lat1, lon2, lat2 = map(radians, [lon1,lat1,lon2,lat2])
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon2/2)**2
    c = 2 * arcsin(sqrt(a))
    km = 6367 * c
    return km

The function above is returning a distance between two geospatial data.

The Graph or Database :

database in MongoDB Compass

The input(sys.arg(v)) is passing a location, and the output is list with sorted nearest distance.

AMC
  • 2,642
  • 7
  • 13
  • 35
  • _What I don't understand is how to perform an iteration over function from an input (sys.arg(v)) into the data frame??._ Can you clarify what you mean? Also, please do not share information as images unless absolutely necessary. See: https://meta.stackoverflow.com/q/303812, https://meta.stackoverflow.com/q/285551, https://idownvotedbecau.se/imageofcode, https://idownvotedbecau.se/imageofanexception/. – AMC Nov 08 '20 at 01:00

1 Answers1

0

It appears that your objective is to find locations nearest to the location input from the command line. This post explains brute force methods as well as more optimized methods like KDTree: Find the nearest point in distance for all the points in the dataset - Python.

The second part of the question is reading landmark information into a DataFrame. In number of cases, json reads directly. But for a more nested json, you can use pandas json_normalize as explained in this post: pandas.io.json.json_normalize with very nested json or this post: https://hackersandslackers.com/json-into-pandas-dataframes/. The later post is a bit long to read, but very useful. If pressed for time skip to the end to see the summary or try this a bit shorter version: https://www.kaggle.com/jboysen/quick-tutorial-flatten-nested-json-in-pandas.

jedi
  • 525
  • 4
  • 11