Advertisement
Kruzar

Untitled

Nov 12th, 2022 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from scipy.spatial import distance
  4.  
  5. avenues_df = pd.DataFrame([0, 153, 307, 524], index=['Park', 'Lexington', '3rd', '2nd'])
  6. streets_df = pd.DataFrame([0, 81, 159, 240, 324], index=['76', '75', '74', '73', '72'])
  7.  
  8. address = ['Lexington', '74']
  9. taxies = [
  10. ['Park', '72'],
  11. ['2nd', '75'],
  12. ['3rd', '76'],
  13. ]
  14.  
  15. address_vector = np.array([avenues_df.loc[address[0]], streets_df.loc[address[1]]])
  16. taxi_distances = []
  17. for i in taxies:
  18. x = np.array([avenues_df.loc[i[0]],streets_df.loc[i[1]]])
  19. taxi_distances.append(distance.cityblock(x, address_vector))
  20.  
  21. taxi_distances = np.array(taxi_distances)
  22.  
  23. index = taxi_distances.argmin()
  24. print(taxies[index])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement