Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- tours = [[0, 4], [0, 5], [0, 6], [1, 13], [2, 0], [3, 8], [4, 9], [5, 10], [6, 7], [7, 1], [8, 2], [9, 3], [10, 11], [11, 14], [12, 0], [13, 12], [14, 0]]
- data = [
- [2, 5.7735, 0.00, 40.0, 16.0],
- [3, 2.8867, 5.00, 40.0, 16.0],
- [4, -2.8868, 5.00, 40.0, 16.0],
- [5, -5.7735, 0.00, 40.0, 16.0],
- [6, -2.8867, -5.00, 40.0, 16.0],
- [7, 2.8868, -5.00, 40.0, 16.0],
- [8, 8.6603, 5.00, 40.0, 24.0],
- [9, 0.0000, 10.00, 40.0, 24.0],
- [10, -8.6603, 5.00, 40.0, 24.0],
- [11, -8.6603, -5.00, 40.0, 24.0],
- [12, 0.0000, -10.00, 40.0, 24.0],
- [13, 8.6603, -5.00, 40.0, 24.0],
- [14, 5.3405, 0.75, 10.0, 10.0],
- [15, 3.3198, 4.25, 10.0, 10.0],
- [16, 6.4952, -1.25, 10.0, 11.0]
- ]
- df = pd.DataFrame(data, columns=['Node', 'X', 'Y', 'Demand', 'Profit'])
- # Creating the new DataFrame
- coord_data = []
- for pair in tours:
- xidx, yidx = pair
- x, y = df.loc[xidx, 'X'], df.loc[yidx, 'Y']
- coord_data.append([x, y])
- # Convert the list to a DataFrame
- coord = pd.DataFrame(coord_data, columns=['X', 'Y'])
- print(coord)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement