{ "cells": [ { "cell_type": "code", "execution_count": 16, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2023-11-07T00:07:54.400654Z", "start_time": "2023-11-07T00:07:54.375821Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "import folium\n", "import utils" ] }, { "cell_type": "code", "execution_count": 17, "outputs": [], "source": [ "# Load the data\n", "ListA = pd.read_csv('List A.csv')\n", "ListB = pd.read_csv('List B.csv')\n", "ListC = pd.read_csv('List C.csv')\n", "ListD = pd.read_csv('List D.csv')" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-07T00:07:54.430515Z", "start_time": "2023-11-07T00:07:54.381537Z" } }, "id": "73b780e762c9de37" }, { "cell_type": "code", "execution_count": 18, "outputs": [], "source": [ "# Create two centroids, one in the North End and one in the Financial District\n", "centroids = [[42.364506, -71.054733], [42.358894, -71.056742]]\n", "\n", "northeastern_coordinate = \"-71.09033,42.33976\"" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-07T00:07:54.431407Z", "start_time": "2023-11-07T00:07:54.392677Z" } }, "id": "65e208650eb43b4" }, { "cell_type": "code", "execution_count": 19, "outputs": [], "source": [ "# Combine the two lists and add a column to indicate the list\n", "ListA['list'] = 'A'\n", "ListB['list'] = 'B'\n", "ListC['list'] = 'C'\n", "ListD['list'] = 'D'\n", "\n", "TotalList = pd.concat([ListA, ListB, ListC])" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-07T00:07:54.431829Z", "start_time": "2023-11-07T00:07:54.397279Z" } }, "id": "ffe4025e97a6c6b9" }, { "cell_type": "code", "execution_count": 20, "outputs": [], "source": [ "# Remove all columns but name and gps\n", "TotalList = TotalList[['name', 'gps', 'list']]" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-07T00:07:54.432180Z", "start_time": "2023-11-07T00:07:54.401907Z" } }, "id": "72657779b4484aae" }, { "cell_type": "code", "execution_count": 21, "outputs": [], "source": [ "# Convert the gps column to a list of lists for k-means\n", "TotalList['gps'] = TotalList['gps'].apply(lambda x: x.strip('[]').split(','))\n", "TotalList['gps'] = TotalList['gps'].apply(lambda x: [float(i) for i in x])" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2023-11-07T00:07:54.432238Z", "start_time": "2023-11-07T00:07:54.405216Z" } }, "id": "a157ffaec020a29a" }, { "cell_type": "code", "execution_count": 22, "outputs": [ { "data": { "text/plain": " name gps list \\\n0 521 Commercial Street #525 [42.3688272, -71.0553792] A \n1 Acorn St [42.3576234, -71.0688746] A \n2 Arlington's Great Meadows [42.4299758, -71.2038948] A \n3 Arthur Fiedler Statue [42.3565057, -71.0754527] A \n4 BU Beach [42.3511927, -71.1060828] A \n.. ... ... ... \n28 The Clam Box [42.2763168, -71.0092883] C \n29 The Partisans [42.3478375, -71.0404428] C \n30 Union Oyster House [42.361288, -71.056908] C \n31 Victoria's Diner [42.3270498, -71.0667744] C \n32 Wollaston Beach [42.2806539, -71.0119933] C \n\n normalized_gps \n0 [0.7251058917247415, 0.8141430878559053] \n1 [0.6747391031099019, 0.778052752104061] \n2 [1.0, 0.41697235794883575] \n3 [0.6697144722136962, 0.7604611403245493] \n4 [0.6458298305822171, 0.6785480000609988] \n.. ... \n28 [0.30922451563130937, 0.9374025730216268] \n29 [0.6307464973238023, 0.8540870458656248] \n30 [0.6912133469876947, 0.8100546647415456] \n31 [0.5372951958288665, 0.7836692527743693] \n32 [0.32872198960456106, 0.9301686741961767] \n\n[131 rows x 4 columns]", "text/html": "
| \n | name | \ngps | \nlist | \nnormalized_gps | \n
|---|---|---|---|---|
| 0 | \n521 Commercial Street #525 | \n[42.3688272, -71.0553792] | \nA | \n[0.7251058917247415, 0.8141430878559053] | \n
| 1 | \nAcorn St | \n[42.3576234, -71.0688746] | \nA | \n[0.6747391031099019, 0.778052752104061] | \n
| 2 | \nArlington's Great Meadows | \n[42.4299758, -71.2038948] | \nA | \n[1.0, 0.41697235794883575] | \n
| 3 | \nArthur Fiedler Statue | \n[42.3565057, -71.0754527] | \nA | \n[0.6697144722136962, 0.7604611403245493] | \n
| 4 | \nBU Beach | \n[42.3511927, -71.1060828] | \nA | \n[0.6458298305822171, 0.6785480000609988] | \n
| ... | \n... | \n... | \n... | \n... | \n
| 28 | \nThe Clam Box | \n[42.2763168, -71.0092883] | \nC | \n[0.30922451563130937, 0.9374025730216268] | \n
| 29 | \nThe Partisans | \n[42.3478375, -71.0404428] | \nC | \n[0.6307464973238023, 0.8540870458656248] | \n
| 30 | \nUnion Oyster House | \n[42.361288, -71.056908] | \nC | \n[0.6912133469876947, 0.8100546647415456] | \n
| 31 | \nVictoria's Diner | \n[42.3270498, -71.0667744] | \nC | \n[0.5372951958288665, 0.7836692527743693] | \n
| 32 | \nWollaston Beach | \n[42.2806539, -71.0119933] | \nC | \n[0.32872198960456106, 0.9301686741961767] | \n
131 rows × 4 columns
\n| \n | waypoint_index | \ntrips_index | \nhint | \ndistance | \nname | \nlocation | \nlat | \nlon | \nroute | \n
|---|---|---|---|---|---|---|---|---|---|
| 0 | \n0 | \n0 | \ndMQAgDTDAIAuAAAAEgAAAAAAAAAAAAAAiaamQKk960AAAA... | \n1.113855 | \nState Street | \n[-71.056741, 42.358884] | \n-71.056741 | \n42.358884 | \n2 | \n
| 13 | \n1 | \n0 | \noLwsgCS9LIBHAAAA2AAAAAAAAABgAQAAkQwAQdo1v0EAAA... | \n2.532529 | \n\n | [-71.056995, 42.36049] | \n-71.056995 | \n42.360490 | \n2 | \n
| 68 | \n2 | \n0 | \nCL0sgBS9LIAhAAAAagAAAAAAAAAAAAAAfoF0QPCwOkEAAA... | \n7.608103 | \n\n | [-71.056994, 42.361263] | \n-71.056994 | \n42.361263 | \n2 | \n
| 40 | \n3 | \n0 | \nYbwsgEO9LIBbAAAAEgAAAAAAAAAPAAAA5ua1QcswjkAAAA... | \n0.468602 | \nCreek Square | \n[-71.056819, 42.361534] | \n-71.056819 | \n42.361534 | \n2 | \n
| 22 | \n4 | \n0 | \nUkAEgFxABIB8AAAAAAAAAAAAAAAYAgAAVjBdQQAAAAAAAA... | \n6.397300 | \n\n | [-71.059255, 42.359295] | \n-71.059255 | \n42.359295 | \n2 | \n
| ... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n
| 14 | \n67 | \n0 | \n-mUsgHZmLIATAAAAYgEAAL0AAADpAAAALf8HQHZ8HUK-9a... | \n55.355565 | \n\n | [-71.049204, 42.325624] | \n-71.049204 | \n42.325624 | \n2 | \n
| 11 | \n68 | \n0 | \n43YhgPN2IYA1AAAAJAAAAAAAAAA5AAAAEha0QWgpbEEAAA... | \n18.896385 | \nLucy Street | \n[-71.06221, 42.324934] | \n-71.062210 | \n42.324934 | \n2 | \n
| 69 | \n69 | \n0 | \nCdQhgB0OA4AYAAAAHgAAADkAAAAAAAAALdMlQdSMQ0Fd0r... | \n10.970598 | \n\n | [-71.066844, 42.327134] | \n-71.066844 | \n42.327134 | \n2 | \n
| 19 | \n70 | \n0 | \nXAAigHIAIoBKAAAASwAAAFUAAABDAQAARGUEQURlBEG2ZR... | \n11.054154 | \n\n | [-71.071196, 42.34085] | \n-71.071196 | \n42.340850 | \n2 | \n
| 71 | \n71 | \n0 | \nDoUhgBeFIYCcAAAAJgAAAAAAAAARAAAAm0CKQdkZiEAAAA... | \n0.236958 | \nNortheastern (Inbound) | \n[-71.090331, 42.339762] | \n-71.090331 | \n42.339762 | \n2 | \n
72 rows × 9 columns
\n