Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- from scipy.spatial import distance
- avenues_df = pd.DataFrame([0, 153, 307, 524], index=['Park', 'Lexington', '3rd', '2nd'])
- streets_df = pd.DataFrame([0, 81, 159, 240, 324], index=['76', '75', '74', '73', '72'])
- address = ['Lexington', '74']
- taxies = [
- ['Park', '72'],
- ['2nd', '75'],
- ['3rd', '76'],
- ]
- address_vector = np.array([avenues_df.loc[address[0]], streets_df.loc[address[1]]])
- taxi_distances = []
- for i in taxies:
- x = np.array([avenues_df.loc[i[0]],streets_df.loc[i[1]]])
- taxi_distances.append(distance.cityblock(x, address_vector))
- taxi_distances = np.array(taxi_distances)
- index = taxi_distances.argmin()
- print(taxies[index])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement