File size: 36,296 Bytes
ecd6340 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import os\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# a = pd.read_csv('./DOT_Traffic_Speeds_NBE.csv')\n",
"# save it as parquet\n",
"# a.to_parquet('./DOT_Traffic_Speeds_NBE.parquet')\n",
"a = pd.read_parquet('./DOT_Traffic_Speeds_NBE.parquet')\n"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"a = a.drop(columns=['ENCODED_POLY_LINE', 'ENCODED_POLY_LINE_LVLS', 'OWNER', 'TRANSCOM_ID', 'LINK_ID'])"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "ID",
"rawType": "int64",
"type": "integer"
},
{
"name": "SPEED",
"rawType": "float64",
"type": "float"
},
{
"name": "TRAVEL_TIME",
"rawType": "int64",
"type": "integer"
},
{
"name": "STATUS",
"rawType": "int64",
"type": "integer"
},
{
"name": "DATA_AS_OF",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_POINTS",
"rawType": "object",
"type": "string"
},
{
"name": "BOROUGH",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_NAME",
"rawType": "object",
"type": "string"
}
],
"conversionMethod": "pd.DataFrame",
"ref": "4c9fbe26-9050-4954-9933-50a4589a7667",
"rows": [
[
"0",
"262",
"34.8",
"359",
"0",
"06/02/2017 11:41:59 PM",
"40.6332305,-74.016151 40.63391,-74.01613 40.6343505,-74.016241 40.63485,-74.016501 40.63533,-74.01694 40.63622,-74.01827 40.6375704,-74.02046 40.63803,-74.021071 40.6385,-74.02146 40.63908,-74.02173 40.63967,-74.02185 40.64036,-74.02172 40.64103,-74.02143",
"Brooklyn",
"GOW S 9TH STREET - 7TH AVENUE"
],
[
"1",
"204",
"55.92",
"155",
"0",
"06/02/2017 11:41:59 PM",
"40.7894406,-73.786291 40.78918,-73.78792 40.78876,-73.789521 40.7882704,-73.790631 40.7872906,-73.79263 40.7866804,-73.7941 40.7864,-73.794901 40.7861204,-73.796241 40.78602,-73.79693 40.78596,-73.79837 40.78615,-73.80182 40.786331,-73.80525 4",
"Queens",
"CIP N TNB - Whitestone Expwy S Exit 14 (Linden Pl)"
],
[
"2",
"106",
"39.77",
"159",
"0",
"06/02/2017 11:41:59 PM",
"40.77158,-73.994441 40.7713004,-73.99455 40.77085,-73.99467 40.76997,-73.99481 40.7701604,-73.99477 40.76986,-73.994831 40.7695406,-73.99496 40.769341,-73.99508 40.768311,-73.9958 40.768311,-73.9958 40.76623,-73.99733 40.76623,-73.99733 40.76547,-73.9979",
"Manhattan",
"12th Ave S 57th St - 45th St"
],
[
"3",
"184",
"65.24",
"39",
"0",
"06/03/2017 04:46:59 AM",
"40.8347204,-73.86593 40.83357,-73.86199 40.8327305,-73.8592 40.8312,-73.85409 40.83017,-73.85069 40.83015,-73.85071 40.8301304,-73.850731 40.8301105,-73.850731",
"Bronx",
"CBE E TAYLOR AVENUE - CASTLE HILL AVENUE"
],
[
"4",
"3",
"14.91",
"422",
"0",
"06/02/2017 11:41:59 PM",
"40.76375,-73.999191 40.763521,-73.99935 40.7620804,-74.00136 40.75985,-74.00306 40.75775,-74.00457 40.75775,-74.00457 40.75576,-74.00601 40.7544904,-74.006921 40.7538404,-74.007241 40.75415,-74.00712 40.7502804,-74.00848 40.74833,-74.007771 40.74114,-74.0",
"Manhattan",
"12th ave @ 45th - 11 ave ganservoort st"
]
],
"shape": {
"columns": 8,
"rows": 5
}
},
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ID</th>\n",
" <th>SPEED</th>\n",
" <th>TRAVEL_TIME</th>\n",
" <th>STATUS</th>\n",
" <th>DATA_AS_OF</th>\n",
" <th>LINK_POINTS</th>\n",
" <th>BOROUGH</th>\n",
" <th>LINK_NAME</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>262</td>\n",
" <td>34.80</td>\n",
" <td>359</td>\n",
" <td>0</td>\n",
" <td>06/02/2017 11:41:59 PM</td>\n",
" <td>40.6332305,-74.016151 40.63391,-74.01613 40.63...</td>\n",
" <td>Brooklyn</td>\n",
" <td>GOW S 9TH STREET - 7TH AVENUE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>204</td>\n",
" <td>55.92</td>\n",
" <td>155</td>\n",
" <td>0</td>\n",
" <td>06/02/2017 11:41:59 PM</td>\n",
" <td>40.7894406,-73.786291 40.78918,-73.78792 40....</td>\n",
" <td>Queens</td>\n",
" <td>CIP N TNB - Whitestone Expwy S Exit 14 (Linden...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>106</td>\n",
" <td>39.77</td>\n",
" <td>159</td>\n",
" <td>0</td>\n",
" <td>06/02/2017 11:41:59 PM</td>\n",
" <td>40.77158,-73.994441 40.7713004,-73.99455 40.77...</td>\n",
" <td>Manhattan</td>\n",
" <td>12th Ave S 57th St - 45th St</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>184</td>\n",
" <td>65.24</td>\n",
" <td>39</td>\n",
" <td>0</td>\n",
" <td>06/03/2017 04:46:59 AM</td>\n",
" <td>40.8347204,-73.86593 40.83357,-73.86199 40.832...</td>\n",
" <td>Bronx</td>\n",
" <td>CBE E TAYLOR AVENUE - CASTLE HILL AVENUE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>3</td>\n",
" <td>14.91</td>\n",
" <td>422</td>\n",
" <td>0</td>\n",
" <td>06/02/2017 11:41:59 PM</td>\n",
" <td>40.76375,-73.999191 40.763521,-73.99935 40.762...</td>\n",
" <td>Manhattan</td>\n",
" <td>12th ave @ 45th - 11 ave ganservoort st</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ID SPEED TRAVEL_TIME STATUS DATA_AS_OF \\\n",
"0 262 34.80 359 0 06/02/2017 11:41:59 PM \n",
"1 204 55.92 155 0 06/02/2017 11:41:59 PM \n",
"2 106 39.77 159 0 06/02/2017 11:41:59 PM \n",
"3 184 65.24 39 0 06/03/2017 04:46:59 AM \n",
"4 3 14.91 422 0 06/02/2017 11:41:59 PM \n",
"\n",
" LINK_POINTS BOROUGH \\\n",
"0 40.6332305,-74.016151 40.63391,-74.01613 40.63... Brooklyn \n",
"1 40.7894406,-73.786291 40.78918,-73.78792 40.... Queens \n",
"2 40.77158,-73.994441 40.7713004,-73.99455 40.77... Manhattan \n",
"3 40.8347204,-73.86593 40.83357,-73.86199 40.832... Bronx \n",
"4 40.76375,-73.999191 40.763521,-73.99935 40.762... Manhattan \n",
"\n",
" LINK_NAME \n",
"0 GOW S 9TH STREET - 7TH AVENUE \n",
"1 CIP N TNB - Whitestone Expwy S Exit 14 (Linden... \n",
"2 12th Ave S 57th St - 45th St \n",
"3 CBE E TAYLOR AVENUE - CASTLE HILL AVENUE \n",
"4 12th ave @ 45th - 11 ave ganservoort st "
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"a['DATA_AS_OF'] = pd.to_datetime(a['DATA_AS_OF'], format='%m/%d/%Y %I:%M:%S %p').dt.strftime('%Y%m%d%H%M%S')"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "ID",
"rawType": "int64",
"type": "integer"
},
{
"name": "SPEED",
"rawType": "float64",
"type": "float"
},
{
"name": "TRAVEL_TIME",
"rawType": "int64",
"type": "integer"
},
{
"name": "STATUS",
"rawType": "int64",
"type": "integer"
},
{
"name": "DATA_AS_OF",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_POINTS",
"rawType": "object",
"type": "string"
},
{
"name": "BOROUGH",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_NAME",
"rawType": "object",
"type": "string"
}
],
"conversionMethod": "pd.DataFrame",
"ref": "1d545d60-5766-4a44-9873-2b42cfb56dfc",
"rows": [
[
"0",
"262",
"34.8",
"359",
"0",
"20170602234159",
"40.6332305,-74.016151 40.63391,-74.01613 40.6343505,-74.016241 40.63485,-74.016501 40.63533,-74.01694 40.63622,-74.01827 40.6375704,-74.02046 40.63803,-74.021071 40.6385,-74.02146 40.63908,-74.02173 40.63967,-74.02185 40.64036,-74.02172 40.64103,-74.02143",
"Brooklyn",
"GOW S 9TH STREET - 7TH AVENUE"
],
[
"1",
"204",
"55.92",
"155",
"0",
"20170602234159",
"40.7894406,-73.786291 40.78918,-73.78792 40.78876,-73.789521 40.7882704,-73.790631 40.7872906,-73.79263 40.7866804,-73.7941 40.7864,-73.794901 40.7861204,-73.796241 40.78602,-73.79693 40.78596,-73.79837 40.78615,-73.80182 40.786331,-73.80525 4",
"Queens",
"CIP N TNB - Whitestone Expwy S Exit 14 (Linden Pl)"
],
[
"2",
"106",
"39.77",
"159",
"0",
"20170602234159",
"40.77158,-73.994441 40.7713004,-73.99455 40.77085,-73.99467 40.76997,-73.99481 40.7701604,-73.99477 40.76986,-73.994831 40.7695406,-73.99496 40.769341,-73.99508 40.768311,-73.9958 40.768311,-73.9958 40.76623,-73.99733 40.76623,-73.99733 40.76547,-73.9979",
"Manhattan",
"12th Ave S 57th St - 45th St"
],
[
"3",
"184",
"65.24",
"39",
"0",
"20170603044659",
"40.8347204,-73.86593 40.83357,-73.86199 40.8327305,-73.8592 40.8312,-73.85409 40.83017,-73.85069 40.83015,-73.85071 40.8301304,-73.850731 40.8301105,-73.850731",
"Bronx",
"CBE E TAYLOR AVENUE - CASTLE HILL AVENUE"
],
[
"4",
"3",
"14.91",
"422",
"0",
"20170602234159",
"40.76375,-73.999191 40.763521,-73.99935 40.7620804,-74.00136 40.75985,-74.00306 40.75775,-74.00457 40.75775,-74.00457 40.75576,-74.00601 40.7544904,-74.006921 40.7538404,-74.007241 40.75415,-74.00712 40.7502804,-74.00848 40.74833,-74.007771 40.74114,-74.0",
"Manhattan",
"12th ave @ 45th - 11 ave ganservoort st"
]
],
"shape": {
"columns": 8,
"rows": 5
}
},
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ID</th>\n",
" <th>SPEED</th>\n",
" <th>TRAVEL_TIME</th>\n",
" <th>STATUS</th>\n",
" <th>DATA_AS_OF</th>\n",
" <th>LINK_POINTS</th>\n",
" <th>BOROUGH</th>\n",
" <th>LINK_NAME</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>262</td>\n",
" <td>34.80</td>\n",
" <td>359</td>\n",
" <td>0</td>\n",
" <td>20170602234159</td>\n",
" <td>40.6332305,-74.016151 40.63391,-74.01613 40.63...</td>\n",
" <td>Brooklyn</td>\n",
" <td>GOW S 9TH STREET - 7TH AVENUE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>204</td>\n",
" <td>55.92</td>\n",
" <td>155</td>\n",
" <td>0</td>\n",
" <td>20170602234159</td>\n",
" <td>40.7894406,-73.786291 40.78918,-73.78792 40....</td>\n",
" <td>Queens</td>\n",
" <td>CIP N TNB - Whitestone Expwy S Exit 14 (Linden...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>106</td>\n",
" <td>39.77</td>\n",
" <td>159</td>\n",
" <td>0</td>\n",
" <td>20170602234159</td>\n",
" <td>40.77158,-73.994441 40.7713004,-73.99455 40.77...</td>\n",
" <td>Manhattan</td>\n",
" <td>12th Ave S 57th St - 45th St</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>184</td>\n",
" <td>65.24</td>\n",
" <td>39</td>\n",
" <td>0</td>\n",
" <td>20170603044659</td>\n",
" <td>40.8347204,-73.86593 40.83357,-73.86199 40.832...</td>\n",
" <td>Bronx</td>\n",
" <td>CBE E TAYLOR AVENUE - CASTLE HILL AVENUE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>3</td>\n",
" <td>14.91</td>\n",
" <td>422</td>\n",
" <td>0</td>\n",
" <td>20170602234159</td>\n",
" <td>40.76375,-73.999191 40.763521,-73.99935 40.762...</td>\n",
" <td>Manhattan</td>\n",
" <td>12th ave @ 45th - 11 ave ganservoort st</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ID SPEED TRAVEL_TIME STATUS DATA_AS_OF \\\n",
"0 262 34.80 359 0 20170602234159 \n",
"1 204 55.92 155 0 20170602234159 \n",
"2 106 39.77 159 0 20170602234159 \n",
"3 184 65.24 39 0 20170603044659 \n",
"4 3 14.91 422 0 20170602234159 \n",
"\n",
" LINK_POINTS BOROUGH \\\n",
"0 40.6332305,-74.016151 40.63391,-74.01613 40.63... Brooklyn \n",
"1 40.7894406,-73.786291 40.78918,-73.78792 40.... Queens \n",
"2 40.77158,-73.994441 40.7713004,-73.99455 40.77... Manhattan \n",
"3 40.8347204,-73.86593 40.83357,-73.86199 40.832... Bronx \n",
"4 40.76375,-73.999191 40.763521,-73.99935 40.762... Manhattan \n",
"\n",
" LINK_NAME \n",
"0 GOW S 9TH STREET - 7TH AVENUE \n",
"1 CIP N TNB - Whitestone Expwy S Exit 14 (Linden... \n",
"2 12th Ave S 57th St - 45th St \n",
"3 CBE E TAYLOR AVENUE - CASTLE HILL AVENUE \n",
"4 12th ave @ 45th - 11 ave ganservoort st "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---------------------------------"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[262,\n",
" 204,\n",
" 106,\n",
" 184,\n",
" 3,\n",
" 2,\n",
" 217,\n",
" 221,\n",
" 1,\n",
" 4,\n",
" 149,\n",
" 150,\n",
" 223,\n",
" 145,\n",
" 450,\n",
" 208,\n",
" 199,\n",
" 207,\n",
" 331,\n",
" 332,\n",
" 169,\n",
" 170,\n",
" 171,\n",
" 315,\n",
" 325,\n",
" 440,\n",
" 330,\n",
" 329,\n",
" 195,\n",
" 345,\n",
" 344,\n",
" 191,\n",
" 213,\n",
" 399,\n",
" 395,\n",
" 410,\n",
" 347,\n",
" 141,\n",
" 140,\n",
" 398,\n",
" 202,\n",
" 168,\n",
" 164,\n",
" 298,\n",
" 451,\n",
" 406,\n",
" 364,\n",
" 417,\n",
" 416,\n",
" 411,\n",
" 264,\n",
" 263,\n",
" 190,\n",
" 448,\n",
" 212,\n",
" 318,\n",
" 211,\n",
" 319,\n",
" 311,\n",
" 419,\n",
" 418,\n",
" 387,\n",
" 385,\n",
" 390,\n",
" 351,\n",
" 388,\n",
" 434,\n",
" 430,\n",
" 431,\n",
" 433,\n",
" 412,\n",
" 413,\n",
" 258,\n",
" 259,\n",
" 394,\n",
" 261,\n",
" 154,\n",
" 155,\n",
" 153,\n",
" 453,\n",
" 428,\n",
" 129,\n",
" 126,\n",
" 295,\n",
" 159,\n",
" 338,\n",
" 427,\n",
" 142,\n",
" 160,\n",
" 185,\n",
" 426,\n",
" 425,\n",
" 110,\n",
" 369,\n",
" 178,\n",
" 422,\n",
" 423,\n",
" 424,\n",
" 165,\n",
" 177,\n",
" 172,\n",
" 167,\n",
" 257,\n",
" 222,\n",
" 379,\n",
" 324,\n",
" 215,\n",
" 383,\n",
" 186,\n",
" 402,\n",
" 265,\n",
" 380,\n",
" 445,\n",
" 119,\n",
" 137,\n",
" 124,\n",
" 365,\n",
" 354,\n",
" 349,\n",
" 205,\n",
" 439,\n",
" 206,\n",
" 405,\n",
" 376,\n",
" 375,\n",
" 381,\n",
" 377,\n",
" 350,\n",
" 378,\n",
" 435,\n",
" 384,\n",
" 441,\n",
" 436,\n",
" 437,\n",
" 382,\n",
" 316,\n",
" 148,\n",
" 157,\n",
" 339,\n",
" 432,\n",
" 389,\n",
" 108,\n",
" 107,\n",
" 225,\n",
" 446,\n",
" 444,\n",
" 224,\n",
" 442,\n",
" 447,\n",
" 443,\n",
" 122,\n",
" 123,\n",
" 313]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# get the unique values of ID\n",
"id_list = a['ID'].unique().tolist()\n",
"id_list"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "ID",
"rawType": "int64",
"type": "integer"
},
{
"name": "SPEED",
"rawType": "float64",
"type": "float"
},
{
"name": "TRAVEL_TIME",
"rawType": "int64",
"type": "integer"
},
{
"name": "STATUS",
"rawType": "int64",
"type": "integer"
},
{
"name": "DATA_AS_OF",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_POINTS",
"rawType": "object",
"type": "string"
},
{
"name": "BOROUGH",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_NAME",
"rawType": "object",
"type": "string"
}
],
"conversionMethod": "pd.DataFrame",
"ref": "88ca17ea-1389-41fa-ba6c-2c211baa054a",
"rows": [
[
"0",
"444",
"0.0",
"0",
"-101",
"19780101000000",
"40.7051105,-74.01663 40.70432,-74.01667 40.7035205,-74.016561 40.70224,-74.015841 40.7016205,-74.01527 40.701401,-74.01473 40.7012804,-74.01399 40.7012,-74.01327 40.701401,-74.012031 40.7018906,-74.00995 40.70306,-74.007731 40.70481,-74.004951 40.70656,-7",
"Manhattan",
"West St S Battery Pl - FDR N Catherine Slip"
],
[
"1",
"444",
"13.05",
"105",
"0",
"20151208152435",
"40.7051105,-74.01663 40.70432,-74.01667 40.7035205,-74.016561 40.70224,-74.015841 40.7016205,-74.01527 40.701401,-74.01473 40.7012804,-74.01399 40.7012,-74.01327 40.701401,-74.012031 40.7018906,-74.00995 40.70306,-74.007731 40.70481,-74.004951 40.70656,-7",
"Manhattan",
"West St S Battery Pl - FDR N Catherine Slip"
]
],
"shape": {
"columns": 8,
"rows": 2
}
},
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ID</th>\n",
" <th>SPEED</th>\n",
" <th>TRAVEL_TIME</th>\n",
" <th>STATUS</th>\n",
" <th>DATA_AS_OF</th>\n",
" <th>LINK_POINTS</th>\n",
" <th>BOROUGH</th>\n",
" <th>LINK_NAME</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>444</td>\n",
" <td>0.00</td>\n",
" <td>0</td>\n",
" <td>-101</td>\n",
" <td>19780101000000</td>\n",
" <td>40.7051105,-74.01663 40.70432,-74.01667 40.703...</td>\n",
" <td>Manhattan</td>\n",
" <td>West St S Battery Pl - FDR N Catherine Slip</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>444</td>\n",
" <td>13.05</td>\n",
" <td>105</td>\n",
" <td>0</td>\n",
" <td>20151208152435</td>\n",
" <td>40.7051105,-74.01663 40.70432,-74.01667 40.703...</td>\n",
" <td>Manhattan</td>\n",
" <td>West St S Battery Pl - FDR N Catherine Slip</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ID SPEED TRAVEL_TIME STATUS DATA_AS_OF \\\n",
"0 444 0.00 0 -101 19780101000000 \n",
"1 444 13.05 105 0 20151208152435 \n",
"\n",
" LINK_POINTS BOROUGH \\\n",
"0 40.7051105,-74.01663 40.70432,-74.01667 40.703... Manhattan \n",
"1 40.7051105,-74.01663 40.70432,-74.01667 40.703... Manhattan \n",
"\n",
" LINK_NAME \n",
"0 West St S Battery Pl - FDR N Catherine Slip \n",
"1 West St S Battery Pl - FDR N Catherine Slip "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = a[a['ID'].apply(str).str.contains(\"444\", regex=False, na=False, case=False)]\n",
"# convert DATA_AS_OF from %m/%d/%Y %I:%M:%S %p to %Y%m%d%H%M%S\n",
"# df['DATA_AS_OF'] = pd.to_datetime(df['DATA_AS_OF'], format='%m/%d/%Y %I:%M:%S %p').dt.strftime('%Y%m%d%H%M%S')\n",
"df = df.sort_values(['DATA_AS_OF'])\n",
"# reset the index\n",
"df = df.reset_index(drop=True)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"doing 262doing 106doing 184doing 3doing 204doing 2doing 221doing 217doing 1doing 4doing 149\n",
"doing 150doing 223\n",
"doing 145\n",
"doing 208doing 450doing 199\n",
"doing 331doing 315doing 332doing 207doing 171doing 170doing 169\n",
"doing 440doing 325\n",
"\n",
"doing 191doing 330\n",
"doing 195doing 329\n",
"doing 345doing 410doing 347doing 344doing 213doing 399doing 398\n",
"\n",
"doing 395doing 164doing 141doing 451\n",
"\n",
"doing 140doing 202\n",
"doing 417doing 264\n",
"\n",
"doing 168doing 411\n",
"doing 406doing 364doing 298doing 190doing 263doing 211\n",
"doing 416doing 318\n",
"\n",
"doing 212\n",
"doing 448doing 311doing 319doing 388\n",
"doing 351doing 419doing 418doing 434doing 390doing 430doing 385\n",
"doing 387doing 258doing 412doing 394\n",
"\n",
"doing 413doing 433doing 431doing 259\n",
"\n",
"doing 428doing 155\n",
"doing 129doing 453doing 126\n",
"\n",
"\n",
"\n",
"doing 261\n",
"doing 154doing 153doing 338\n",
"doing 185\n",
"doing 425\n",
"doing 160doing 427doing 142doing 426\n",
"\n",
"doing 178doing 422\n",
"doing 424doing 165doing 369\n",
"doing 423\n",
"\n",
"doing 177\n",
"doing 110\n",
"\n",
"doing 172doing 167\n",
"doing 215\n",
"\n",
"doing 379doing 222\n",
"\n",
"\n",
"\n",
"\n",
"doing 383doing 257doing 265doing 324doing 380\n",
"doing 445doing 119\n",
"\n",
"\n",
"doing 137doing 124\n",
"doing 402doing 186\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"doing 349\n",
"doing 354\n",
"doing 365doing 205\n",
"doing 206\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"doing 405\n",
"\n",
"\n",
"doing 381doing 439\n",
"doing 350doing 377\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"doing 376doing 375\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"doing 295\n",
"doing 159\n",
"\n",
"\n",
"\n",
"doing 378\n",
"doing 435\n",
"doing 384\n",
"doing 441\n",
"doing 436\n",
"doing 437\n",
"doing 382\n",
"doing 316\n",
"doing 148\n",
"doing 157\n",
"doing 339\n",
"doing 432\n",
"doing 389\n",
"doing 108\n",
"doing 107\n",
"doing 225\n",
"doing 446\n",
"doing 444\n",
"doing 224\n",
"doing 442\n",
"doing 447\n",
"doing 443\n",
"doing 122\n",
"doing 123\n",
"doing 313\n"
]
}
],
"source": [
"from multiprocessing import Pool\n",
"\n",
"os.makedirs('./full_data', exist_ok=True)\n",
"os.makedirs('./slim_data', exist_ok=True)\n",
"\n",
"def process_id(id):\n",
" print(f'doing {id}')\n",
" # filter the data by id\n",
" df = a[a['ID'] == id]\n",
" \n",
" # convert DATA_AS_OF from %m/%d/%Y %I:%M:%S %p to %Y%m%d%H%M%S\n",
" df = df.sort_values(['DATA_AS_OF'])\n",
" # reset the index\n",
" df = df.reset_index(drop=True)\n",
" df.to_parquet('./full_data/id_{}.parquet'.format(id))\n",
" # get the value of BOROUGH column of first raw\n",
" borough = df['BOROUGH'].iloc[0]\n",
" link = df['LINK_NAME'].iloc[0]\n",
" length = len(df)\n",
" id_info = {id: {'borough': borough, 'link': link, 'len': length}}\n",
" df = df.drop(columns=['BOROUGH', 'LINK_NAME', 'ID','LINK_POINTS', 'STATUS'])\n",
" # rearrange the columns\n",
" df = df[['DATA_AS_OF', 'SPEED', 'TRAVEL_TIME']]\n",
" df.to_parquet('./slim_data/id_{}.parquet'.format(id))\n",
" return id_info\n",
"\n",
"with Pool() as pool:\n",
" results = pool.map(process_id, id_list)\n",
"\n",
"# Combine all the id_info dictionaries into one\n",
"id_info = {}\n",
"for result in results:\n",
" id_info.update(result)\n",
"\n",
"with open('./id_info.json', 'w') as f:\n",
" json.dump(id_info, f)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.microsoft.datawrangler.viewer.v0+json": {
"columns": [
{
"name": "index",
"rawType": "int64",
"type": "integer"
},
{
"name": "ID",
"rawType": "int64",
"type": "integer"
},
{
"name": "SPEED",
"rawType": "float64",
"type": "float"
},
{
"name": "TRAVEL_TIME",
"rawType": "int64",
"type": "integer"
},
{
"name": "STATUS",
"rawType": "int64",
"type": "integer"
},
{
"name": "DATA_AS_OF",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_POINTS",
"rawType": "object",
"type": "string"
},
{
"name": "BOROUGH",
"rawType": "object",
"type": "string"
},
{
"name": "LINK_NAME",
"rawType": "object",
"type": "string"
}
],
"conversionMethod": "pd.DataFrame",
"ref": "ebc49528-2e7d-4a5d-9cb1-fc940f203bea",
"rows": [
[
"0",
"444",
"0.0",
"0",
"-101",
"19780101000000",
"40.7051105,-74.01663 40.70432,-74.01667 40.7035205,-74.016561 40.70224,-74.015841 40.7016205,-74.01527 40.701401,-74.01473 40.7012804,-74.01399 40.7012,-74.01327 40.701401,-74.012031 40.7018906,-74.00995 40.70306,-74.007731 40.70481,-74.004951 40.70656,-7",
"Manhattan",
"West St S Battery Pl - FDR N Catherine Slip"
],
[
"1",
"444",
"13.05",
"105",
"0",
"20151208152435",
"40.7051105,-74.01663 40.70432,-74.01667 40.7035205,-74.016561 40.70224,-74.015841 40.7016205,-74.01527 40.701401,-74.01473 40.7012804,-74.01399 40.7012,-74.01327 40.701401,-74.012031 40.7018906,-74.00995 40.70306,-74.007731 40.70481,-74.004951 40.70656,-7",
"Manhattan",
"West St S Battery Pl - FDR N Catherine Slip"
]
],
"shape": {
"columns": 8,
"rows": 2
}
},
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>ID</th>\n",
" <th>SPEED</th>\n",
" <th>TRAVEL_TIME</th>\n",
" <th>STATUS</th>\n",
" <th>DATA_AS_OF</th>\n",
" <th>LINK_POINTS</th>\n",
" <th>BOROUGH</th>\n",
" <th>LINK_NAME</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>444</td>\n",
" <td>0.00</td>\n",
" <td>0</td>\n",
" <td>-101</td>\n",
" <td>19780101000000</td>\n",
" <td>40.7051105,-74.01663 40.70432,-74.01667 40.703...</td>\n",
" <td>Manhattan</td>\n",
" <td>West St S Battery Pl - FDR N Catherine Slip</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>444</td>\n",
" <td>13.05</td>\n",
" <td>105</td>\n",
" <td>0</td>\n",
" <td>20151208152435</td>\n",
" <td>40.7051105,-74.01663 40.70432,-74.01667 40.703...</td>\n",
" <td>Manhattan</td>\n",
" <td>West St S Battery Pl - FDR N Catherine Slip</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" ID SPEED TRAVEL_TIME STATUS DATA_AS_OF \\\n",
"0 444 0.00 0 -101 19780101000000 \n",
"1 444 13.05 105 0 20151208152435 \n",
"\n",
" LINK_POINTS BOROUGH \\\n",
"0 40.7051105,-74.01663 40.70432,-74.01667 40.703... Manhattan \n",
"1 40.7051105,-74.01663 40.70432,-74.01667 40.703... Manhattan \n",
"\n",
" LINK_NAME \n",
"0 West St S Battery Pl - FDR N Catherine Slip \n",
"1 West St S Battery Pl - FDR N Catherine Slip "
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# convert the DATA_AS_OF to datetime\n",
"\n",
"df"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "probts",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|