File size: 43,359 Bytes
9be4956 |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "a10c60c4",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"data = pd.read_csv('/home/xj/toolAugEnv/code/toolConstraint/database/flights/Combined_Flights_2022.csv')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "1c12a0f0",
"metadata": {},
"outputs": [
{
"data": {
"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>FlightDate</th>\n",
" <th>Airline</th>\n",
" <th>Origin</th>\n",
" <th>Dest</th>\n",
" <th>Cancelled</th>\n",
" <th>Diverted</th>\n",
" <th>CRSDepTime</th>\n",
" <th>DepTime</th>\n",
" <th>DepDelayMinutes</th>\n",
" <th>DepDelay</th>\n",
" <th>...</th>\n",
" <th>WheelsOff</th>\n",
" <th>WheelsOn</th>\n",
" <th>TaxiIn</th>\n",
" <th>CRSArrTime</th>\n",
" <th>ArrDelay</th>\n",
" <th>ArrDel15</th>\n",
" <th>ArrivalDelayGroups</th>\n",
" <th>ArrTimeBlk</th>\n",
" <th>DistanceGroup</th>\n",
" <th>DivAirportLandings</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2022-04-04</td>\n",
" <td>Commutair Aka Champlain Enterprises, Inc.</td>\n",
" <td>GJT</td>\n",
" <td>DEN</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>1133</td>\n",
" <td>1123.0</td>\n",
" <td>0.0</td>\n",
" <td>-10.0</td>\n",
" <td>...</td>\n",
" <td>1140.0</td>\n",
" <td>1220.0</td>\n",
" <td>8.0</td>\n",
" <td>1245</td>\n",
" <td>-17.0</td>\n",
" <td>0.0</td>\n",
" <td>-2.0</td>\n",
" <td>1200-1259</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2022-04-04</td>\n",
" <td>Commutair Aka Champlain Enterprises, Inc.</td>\n",
" <td>HRL</td>\n",
" <td>IAH</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>732</td>\n",
" <td>728.0</td>\n",
" <td>0.0</td>\n",
" <td>-4.0</td>\n",
" <td>...</td>\n",
" <td>744.0</td>\n",
" <td>839.0</td>\n",
" <td>9.0</td>\n",
" <td>849</td>\n",
" <td>-1.0</td>\n",
" <td>0.0</td>\n",
" <td>-1.0</td>\n",
" <td>0800-0859</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2022-04-04</td>\n",
" <td>Commutair Aka Champlain Enterprises, Inc.</td>\n",
" <td>DRO</td>\n",
" <td>DEN</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>1529</td>\n",
" <td>1514.0</td>\n",
" <td>0.0</td>\n",
" <td>-15.0</td>\n",
" <td>...</td>\n",
" <td>1535.0</td>\n",
" <td>1622.0</td>\n",
" <td>14.0</td>\n",
" <td>1639</td>\n",
" <td>-3.0</td>\n",
" <td>0.0</td>\n",
" <td>-1.0</td>\n",
" <td>1600-1659</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2022-04-04</td>\n",
" <td>Commutair Aka Champlain Enterprises, Inc.</td>\n",
" <td>IAH</td>\n",
" <td>GPT</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>1435</td>\n",
" <td>1430.0</td>\n",
" <td>0.0</td>\n",
" <td>-5.0</td>\n",
" <td>...</td>\n",
" <td>1446.0</td>\n",
" <td>1543.0</td>\n",
" <td>4.0</td>\n",
" <td>1605</td>\n",
" <td>-18.0</td>\n",
" <td>0.0</td>\n",
" <td>-2.0</td>\n",
" <td>1600-1659</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2022-04-04</td>\n",
" <td>Commutair Aka Champlain Enterprises, Inc.</td>\n",
" <td>DRO</td>\n",
" <td>DEN</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>1135</td>\n",
" <td>1135.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>...</td>\n",
" <td>1154.0</td>\n",
" <td>1243.0</td>\n",
" <td>8.0</td>\n",
" <td>1245</td>\n",
" <td>6.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1200-1259</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078313</th>\n",
" <td>2022-03-31</td>\n",
" <td>Republic Airlines</td>\n",
" <td>MSY</td>\n",
" <td>EWR</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>1949</td>\n",
" <td>2014.0</td>\n",
" <td>25.0</td>\n",
" <td>25.0</td>\n",
" <td>...</td>\n",
" <td>2031.0</td>\n",
" <td>202.0</td>\n",
" <td>32.0</td>\n",
" <td>2354</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2300-2359</td>\n",
" <td>5</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078314</th>\n",
" <td>2022-03-17</td>\n",
" <td>Republic Airlines</td>\n",
" <td>CLT</td>\n",
" <td>EWR</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>1733</td>\n",
" <td>1817.0</td>\n",
" <td>44.0</td>\n",
" <td>44.0</td>\n",
" <td>...</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>1942</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>1900-1959</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078315</th>\n",
" <td>2022-03-08</td>\n",
" <td>Republic Airlines</td>\n",
" <td>ALB</td>\n",
" <td>ORD</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>1700</td>\n",
" <td>2318.0</td>\n",
" <td>378.0</td>\n",
" <td>378.0</td>\n",
" <td>...</td>\n",
" <td>2337.0</td>\n",
" <td>52.0</td>\n",
" <td>7.0</td>\n",
" <td>1838</td>\n",
" <td>381.0</td>\n",
" <td>1.0</td>\n",
" <td>12.0</td>\n",
" <td>1800-1859</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078316</th>\n",
" <td>2022-03-25</td>\n",
" <td>Republic Airlines</td>\n",
" <td>EWR</td>\n",
" <td>PIT</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>2129</td>\n",
" <td>2322.0</td>\n",
" <td>113.0</td>\n",
" <td>113.0</td>\n",
" <td>...</td>\n",
" <td>2347.0</td>\n",
" <td>933.0</td>\n",
" <td>6.0</td>\n",
" <td>2255</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>2200-2259</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078317</th>\n",
" <td>2022-03-07</td>\n",
" <td>Republic Airlines</td>\n",
" <td>EWR</td>\n",
" <td>RDU</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>1154</td>\n",
" <td>1148.0</td>\n",
" <td>0.0</td>\n",
" <td>-6.0</td>\n",
" <td>...</td>\n",
" <td>1201.0</td>\n",
" <td>1552.0</td>\n",
" <td>4.0</td>\n",
" <td>1333</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>1300-1359</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>4078318 rows × 61 columns</p>\n",
"</div>"
],
"text/plain": [
" FlightDate Airline Origin Dest \\\n",
"0 2022-04-04 Commutair Aka Champlain Enterprises, Inc. GJT DEN \n",
"1 2022-04-04 Commutair Aka Champlain Enterprises, Inc. HRL IAH \n",
"2 2022-04-04 Commutair Aka Champlain Enterprises, Inc. DRO DEN \n",
"3 2022-04-04 Commutair Aka Champlain Enterprises, Inc. IAH GPT \n",
"4 2022-04-04 Commutair Aka Champlain Enterprises, Inc. DRO DEN \n",
"... ... ... ... ... \n",
"4078313 2022-03-31 Republic Airlines MSY EWR \n",
"4078314 2022-03-17 Republic Airlines CLT EWR \n",
"4078315 2022-03-08 Republic Airlines ALB ORD \n",
"4078316 2022-03-25 Republic Airlines EWR PIT \n",
"4078317 2022-03-07 Republic Airlines EWR RDU \n",
"\n",
" Cancelled Diverted CRSDepTime DepTime DepDelayMinutes DepDelay \\\n",
"0 False False 1133 1123.0 0.0 -10.0 \n",
"1 False False 732 728.0 0.0 -4.0 \n",
"2 False False 1529 1514.0 0.0 -15.0 \n",
"3 False False 1435 1430.0 0.0 -5.0 \n",
"4 False False 1135 1135.0 0.0 0.0 \n",
"... ... ... ... ... ... ... \n",
"4078313 False True 1949 2014.0 25.0 25.0 \n",
"4078314 True False 1733 1817.0 44.0 44.0 \n",
"4078315 False False 1700 2318.0 378.0 378.0 \n",
"4078316 False True 2129 2322.0 113.0 113.0 \n",
"4078317 False True 1154 1148.0 0.0 -6.0 \n",
"\n",
" ... WheelsOff WheelsOn TaxiIn CRSArrTime ArrDelay ArrDel15 \\\n",
"0 ... 1140.0 1220.0 8.0 1245 -17.0 0.0 \n",
"1 ... 744.0 839.0 9.0 849 -1.0 0.0 \n",
"2 ... 1535.0 1622.0 14.0 1639 -3.0 0.0 \n",
"3 ... 1446.0 1543.0 4.0 1605 -18.0 0.0 \n",
"4 ... 1154.0 1243.0 8.0 1245 6.0 0.0 \n",
"... ... ... ... ... ... ... ... \n",
"4078313 ... 2031.0 202.0 32.0 2354 NaN NaN \n",
"4078314 ... NaN NaN NaN 1942 NaN NaN \n",
"4078315 ... 2337.0 52.0 7.0 1838 381.0 1.0 \n",
"4078316 ... 2347.0 933.0 6.0 2255 NaN NaN \n",
"4078317 ... 1201.0 1552.0 4.0 1333 NaN NaN \n",
"\n",
" ArrivalDelayGroups ArrTimeBlk DistanceGroup DivAirportLandings \n",
"0 -2.0 1200-1259 1 0 \n",
"1 -1.0 0800-0859 2 0 \n",
"2 -1.0 1600-1659 2 0 \n",
"3 -2.0 1600-1659 2 0 \n",
"4 0.0 1200-1259 2 0 \n",
"... ... ... ... ... \n",
"4078313 NaN 2300-2359 5 1 \n",
"4078314 NaN 1900-1959 3 0 \n",
"4078315 12.0 1800-1859 3 0 \n",
"4078316 NaN 2200-2259 2 1 \n",
"4078317 NaN 1300-1359 2 1 \n",
"\n",
"[4078318 rows x 61 columns]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "e572970c",
"metadata": {},
"outputs": [],
"source": [
"str_data = data.astype(str)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "27a7cd6b",
"metadata": {},
"outputs": [],
"source": [
"column_names = ', '.join(data.columns.tolist())"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a5cf51cc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'FlightDate, Airline, Origin, Dest, Cancelled, Diverted, CRSDepTime, DepTime, DepDelayMinutes, DepDelay, ArrTime, ArrDelayMinutes, AirTime, CRSElapsedTime, ActualElapsedTime, Distance, Year, Quarter, Month, DayofMonth, DayOfWeek, Marketing_Airline_Network, Operated_or_Branded_Code_Share_Partners, DOT_ID_Marketing_Airline, IATA_Code_Marketing_Airline, Flight_Number_Marketing_Airline, Operating_Airline, DOT_ID_Operating_Airline, IATA_Code_Operating_Airline, Tail_Number, Flight_Number_Operating_Airline, OriginAirportID, OriginAirportSeqID, OriginCityMarketID, OriginCityName, OriginState, OriginStateFips, OriginStateName, OriginWac, DestAirportID, DestAirportSeqID, DestCityMarketID, DestCityName, DestState, DestStateFips, DestStateName, DestWac, DepDel15, DepartureDelayGroups, DepTimeBlk, TaxiOut, WheelsOff, WheelsOn, TaxiIn, CRSArrTime, ArrDelay, ArrDel15, ArrivalDelayGroups, ArrTimeBlk, DistanceGroup, DivAirportLandings'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"column_names"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "061d3979",
"metadata": {},
"outputs": [],
"source": [
"pd.options.display.max_rows = 300"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "e44254fc",
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"FlightDate 2022-04-04\n",
"Airline Commutair Aka Champlain Enterprises, Inc.\n",
"Origin DEN\n",
"Dest CPR\n",
"Cancelled False\n",
"Diverted False\n",
"CRSDepTime 1540\n",
"DepTime 1546.0\n",
"DepDelayMinutes 6.0\n",
"DepDelay 6.0\n",
"ArrTime 1650.0\n",
"ArrDelayMinutes 0.0\n",
"AirTime 45.0\n",
"CRSElapsedTime 70.0\n",
"ActualElapsedTime 64.0\n",
"Distance 230.0\n",
"Year 2022\n",
"Quarter 2\n",
"Month 4\n",
"DayofMonth 4\n",
"DayOfWeek 1\n",
"Marketing_Airline_Network UA\n",
"Operated_or_Branded_Code_Share_Partners UA_CODESHARE\n",
"DOT_ID_Marketing_Airline 19977\n",
"IATA_Code_Marketing_Airline UA\n",
"Flight_Number_Marketing_Airline 4288\n",
"Operating_Airline C5\n",
"DOT_ID_Operating_Airline 20445\n",
"IATA_Code_Operating_Airline C5\n",
"Tail_Number N14177\n",
"Flight_Number_Operating_Airline 4288\n",
"OriginAirportID 11292\n",
"OriginAirportSeqID 1129202\n",
"OriginCityMarketID 30325\n",
"OriginCityName Denver, CO\n",
"OriginState CO\n",
"OriginStateFips 8\n",
"OriginStateName Colorado\n",
"OriginWac 82\n",
"DestAirportID 11122\n",
"DestAirportSeqID 1112205\n",
"DestCityMarketID 31122\n",
"DestCityName Casper, WY\n",
"DestState WY\n",
"DestStateFips 56\n",
"DestStateName Wyoming\n",
"DestWac 88\n",
"DepDel15 0.0\n",
"DepartureDelayGroups 0.0\n",
"DepTimeBlk 1500-1559\n",
"TaxiOut 13.0\n",
"WheelsOff 1559.0\n",
"WheelsOn 1644.0\n",
"TaxiIn 6.0\n",
"CRSArrTime 1650\n",
"ArrDelay 0.0\n",
"ArrDel15 0.0\n",
"ArrivalDelayGroups 0.0\n",
"ArrTimeBlk 1600-1659\n",
"DistanceGroup 1\n",
"DivAirportLandings 0\n",
"Name: 10, dtype: object\n"
]
}
],
"source": [
"print(data.iloc[10],flush=True)"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "1a0f208d",
"metadata": {},
"outputs": [],
"source": [
"filter_data = data[['FlightDate','DepTime','ArrTime','Distance','OriginCityName','DestCityName']]"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "4cf6383d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"FlightDate\n",
"DepTime\n",
"ArrTime\n",
"Distance\n",
"OriginCityName\n",
"DestCityName\n"
]
}
],
"source": [
"for unit in filter_data:\n",
" print(unit)"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "ddbf175a",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fc2986be7e664907986359e2bcf22671",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"IOPub message rate exceeded.\n",
"The notebook server will temporarily stop sending output\n",
"to the client in order to avoid crashing it.\n",
"To change this limit, set the config variable\n",
"`--NotebookApp.iopub_msg_rate_limit`.\n",
"\n",
"Current values:\n",
"NotebookApp.iopub_msg_rate_limit=1000.0 (msgs/sec)\n",
"NotebookApp.rate_limit_window=3.0 (secs)\n",
"\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[63], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtqdm\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mautonotebook\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m tqdm\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m idx, unit \u001b[38;5;129;01min\u001b[39;00m tqdm(\u001b[38;5;28menumerate\u001b[39m(filter_data\u001b[38;5;241m.\u001b[39miterrows())):\n\u001b[0;32m----> 3\u001b[0m \u001b[43mfilter_data\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloc\u001b[49m\u001b[43m[\u001b[49m\u001b[43midx\u001b[49m\u001b[43m,\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mOriginCityName\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m unit[\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOriginCityName\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39msplit(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m,\u001b[39m\u001b[38;5;124m'\u001b[39m)[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 4\u001b[0m filter_data\u001b[38;5;241m.\u001b[39mloc[idx,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mDestCityName\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m unit[\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mDestCityName\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39msplit(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m,\u001b[39m\u001b[38;5;124m'\u001b[39m)[\u001b[38;5;241m0\u001b[39m]\n\u001b[1;32m 5\u001b[0m filter_data\u001b[38;5;241m.\u001b[39mloc[idx,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mprice\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m((unit[\u001b[38;5;241m1\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mDistance\u001b[39m\u001b[38;5;124m'\u001b[39m]) \u001b[38;5;241m*\u001b[39m random\u001b[38;5;241m.\u001b[39muniform(\u001b[38;5;241m0.2\u001b[39m,\u001b[38;5;241m0.5\u001b[39m))\n",
"File \u001b[0;32m~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/indexing.py:849\u001b[0m, in \u001b[0;36m_LocationIndexer.__setitem__\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 846\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_has_valid_setitem_indexer(key)\n\u001b[1;32m 848\u001b[0m iloc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mname \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124miloc\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\u001b[38;5;241m.\u001b[39miloc\n\u001b[0;32m--> 849\u001b[0m \u001b[43miloc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_setitem_with_indexer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mindexer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/indexing.py:1835\u001b[0m, in \u001b[0;36m_iLocIndexer._setitem_with_indexer\u001b[0;34m(self, indexer, value, name)\u001b[0m\n\u001b[1;32m 1832\u001b[0m \u001b[38;5;66;03m# align and set the values\u001b[39;00m\n\u001b[1;32m 1833\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m take_split_path:\n\u001b[1;32m 1834\u001b[0m \u001b[38;5;66;03m# We have to operate column-wise\u001b[39;00m\n\u001b[0;32m-> 1835\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_setitem_with_indexer_split_path\u001b[49m\u001b[43m(\u001b[49m\u001b[43mindexer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1836\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1837\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_setitem_single_block(indexer, value, name)\n",
"File \u001b[0;32m~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/indexing.py:1928\u001b[0m, in \u001b[0;36m_iLocIndexer._setitem_with_indexer_split_path\u001b[0;34m(self, indexer, value, name)\u001b[0m\n\u001b[1;32m 1925\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1926\u001b[0m \u001b[38;5;66;03m# scalar value\u001b[39;00m\n\u001b[1;32m 1927\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m loc \u001b[38;5;129;01min\u001b[39;00m ilocs:\n\u001b[0;32m-> 1928\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_setitem_single_column\u001b[49m\u001b[43m(\u001b[49m\u001b[43mloc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpi\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/indexing.py:2034\u001b[0m, in \u001b[0;36m_iLocIndexer._setitem_single_column\u001b[0;34m(self, loc, value, plane_indexer)\u001b[0m\n\u001b[1;32m 2030\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\u001b[38;5;241m.\u001b[39misetitem(loc, value)\n\u001b[1;32m 2031\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 2032\u001b[0m \u001b[38;5;66;03m# set value into the column (first attempting to operate inplace, then\u001b[39;00m\n\u001b[1;32m 2033\u001b[0m \u001b[38;5;66;03m# falling back to casting if necessary)\u001b[39;00m\n\u001b[0;32m-> 2034\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mobj\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_mgr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcolumn_setitem\u001b[49m\u001b[43m(\u001b[49m\u001b[43mloc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mplane_indexer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2036\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\u001b[38;5;241m.\u001b[39m_clear_item_cache()\n",
"File \u001b[0;32m~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/internals/managers.py:1385\u001b[0m, in \u001b[0;36mBlockManager.column_setitem\u001b[0;34m(self, loc, idx, value, inplace_only)\u001b[0m\n\u001b[1;32m 1383\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1384\u001b[0m new_mgr \u001b[38;5;241m=\u001b[39m col_mgr\u001b[38;5;241m.\u001b[39msetitem((idx,), value)\n\u001b[0;32m-> 1385\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43miset\u001b[49m\u001b[43m(\u001b[49m\u001b[43mloc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnew_mgr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_block\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalues\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minplace\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/internals/managers.py:1213\u001b[0m, in \u001b[0;36mBlockManager.iset\u001b[0;34m(self, loc, value, inplace)\u001b[0m\n\u001b[1;32m 1211\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_iset_split_block(blkno_l, blk_locs, value_getitem(val_locs))\n\u001b[1;32m 1212\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m-> 1213\u001b[0m \u001b[43mblk\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mset_inplace\u001b[49m\u001b[43m(\u001b[49m\u001b[43mblk_locs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue_getitem\u001b[49m\u001b[43m(\u001b[49m\u001b[43mval_locs\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1214\u001b[0m \u001b[38;5;28;01mcontinue\u001b[39;00m\n\u001b[1;32m 1215\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"File \u001b[0;32m~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/internals/blocks.py:924\u001b[0m, in \u001b[0;36mBlock.set_inplace\u001b[0;34m(self, locs, values, copy)\u001b[0m\n\u001b[1;32m 922\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m copy:\n\u001b[1;32m 923\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalues \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalues\u001b[38;5;241m.\u001b[39mcopy()\n\u001b[0;32m--> 924\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalues\u001b[49m\u001b[43m[\u001b[49m\u001b[43mlocs\u001b[49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m values\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"from tqdm.autonotebook import tqdm\n",
"for idx, unit in tqdm(enumerate(filter_data.iterrows())):\n",
" filter_data.loc[idx,'OriginCityName'] = unit[1]['OriginCityName'].split(',')[0]\n",
" filter_data.loc[idx,'DestCityName'] = unit[1]['DestCityName'].split(',')[0]\n",
" filter_data.loc[idx,'price'] = int((unit[1]['Distance']) * random.uniform(0.2,0.5))"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "0ac9a59d",
"metadata": {},
"outputs": [
{
"data": {
"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>FlightDate</th>\n",
" <th>DepTime</th>\n",
" <th>ArrTime</th>\n",
" <th>Distance</th>\n",
" <th>OriginCityName</th>\n",
" <th>DestCityName</th>\n",
" <th>price</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2022-04-04</td>\n",
" <td>1123.0</td>\n",
" <td>1228.0</td>\n",
" <td>212.0</td>\n",
" <td>Grand Junction</td>\n",
" <td>Denver</td>\n",
" <td>72.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2022-04-04</td>\n",
" <td>728.0</td>\n",
" <td>848.0</td>\n",
" <td>295.0</td>\n",
" <td>Harlingen/San Benito</td>\n",
" <td>Houston</td>\n",
" <td>141.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2022-04-04</td>\n",
" <td>1514.0</td>\n",
" <td>1636.0</td>\n",
" <td>251.0</td>\n",
" <td>Durango</td>\n",
" <td>Denver</td>\n",
" <td>114.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2022-04-04</td>\n",
" <td>1430.0</td>\n",
" <td>1547.0</td>\n",
" <td>376.0</td>\n",
" <td>Houston</td>\n",
" <td>Gulfport/Biloxi</td>\n",
" <td>103.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2022-04-04</td>\n",
" <td>1135.0</td>\n",
" <td>1251.0</td>\n",
" <td>251.0</td>\n",
" <td>Durango</td>\n",
" <td>Denver</td>\n",
" <td>118.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078313</th>\n",
" <td>2022-03-31</td>\n",
" <td>2014.0</td>\n",
" <td>234.0</td>\n",
" <td>1167.0</td>\n",
" <td>New Orleans, LA</td>\n",
" <td>Newark, NJ</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078314</th>\n",
" <td>2022-03-17</td>\n",
" <td>1817.0</td>\n",
" <td>NaN</td>\n",
" <td>529.0</td>\n",
" <td>Charlotte, NC</td>\n",
" <td>Newark, NJ</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078315</th>\n",
" <td>2022-03-08</td>\n",
" <td>2318.0</td>\n",
" <td>59.0</td>\n",
" <td>723.0</td>\n",
" <td>Albany, NY</td>\n",
" <td>Chicago, IL</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078316</th>\n",
" <td>2022-03-25</td>\n",
" <td>2322.0</td>\n",
" <td>939.0</td>\n",
" <td>319.0</td>\n",
" <td>Newark, NJ</td>\n",
" <td>Pittsburgh, PA</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4078317</th>\n",
" <td>2022-03-07</td>\n",
" <td>1148.0</td>\n",
" <td>1556.0</td>\n",
" <td>416.0</td>\n",
" <td>Newark, NJ</td>\n",
" <td>Raleigh/Durham, NC</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>4078318 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" FlightDate DepTime ArrTime Distance OriginCityName \\\n",
"0 2022-04-04 1123.0 1228.0 212.0 Grand Junction \n",
"1 2022-04-04 728.0 848.0 295.0 Harlingen/San Benito \n",
"2 2022-04-04 1514.0 1636.0 251.0 Durango \n",
"3 2022-04-04 1430.0 1547.0 376.0 Houston \n",
"4 2022-04-04 1135.0 1251.0 251.0 Durango \n",
"... ... ... ... ... ... \n",
"4078313 2022-03-31 2014.0 234.0 1167.0 New Orleans, LA \n",
"4078314 2022-03-17 1817.0 NaN 529.0 Charlotte, NC \n",
"4078315 2022-03-08 2318.0 59.0 723.0 Albany, NY \n",
"4078316 2022-03-25 2322.0 939.0 319.0 Newark, NJ \n",
"4078317 2022-03-07 1148.0 1556.0 416.0 Newark, NJ \n",
"\n",
" DestCityName price \n",
"0 Denver 72.0 \n",
"1 Houston 141.0 \n",
"2 Denver 114.0 \n",
"3 Gulfport/Biloxi 103.0 \n",
"4 Denver 118.0 \n",
"... ... ... \n",
"4078313 Newark, NJ NaN \n",
"4078314 Newark, NJ NaN \n",
"4078315 Chicago, IL NaN \n",
"4078316 Pittsburgh, PA NaN \n",
"4078317 Raleigh/Durham, NC NaN \n",
"\n",
"[4078318 rows x 7 columns]"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"filter_data"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "10a2b0e3",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b7bbe97af9df406fb0e56a6f8dfd8656",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, FlightDate 2022-04-04\n",
"DepTime 1123.0\n",
"ArrTime 1228.0\n",
"Distance 212.0\n",
"OriginCityName Grand Junction\n",
"DestCityName Denver\n",
"Name: 0, dtype: object)\n"
]
}
],
"source": [
"import random\n",
"for idx, unit in tqdm(enumerate(filter_data.iterrows())):\n",
" filter_data.loc[idx,'price'] = eval(unit[1]['Distance']) * random.uniform(0.2,0.5))"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "1ca1f597",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_1504075/2172656540.py:1: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" filter_data['price'] = None\n"
]
}
],
"source": [
"filter_data['price'] = None"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e32d2e3c",
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"random.uniform(0.2,0.5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf4ecc5e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|