|
15 | 15 | }, |
16 | 16 | { |
17 | 17 | "cell_type": "code", |
18 | | - "execution_count": 9, |
| 18 | + "execution_count": 1, |
19 | 19 | "metadata": {}, |
20 | 20 | "outputs": [], |
21 | 21 | "source": [ |
|
25 | 25 | }, |
26 | 26 | { |
27 | 27 | "cell_type": "code", |
28 | | - "execution_count": 10, |
| 28 | + "execution_count": 2, |
29 | 29 | "metadata": {}, |
30 | 30 | "outputs": [ |
31 | 31 | { |
|
166 | 166 | "4 0 373450 8.0500 NaN S " |
167 | 167 | ] |
168 | 168 | }, |
169 | | - "execution_count": 10, |
| 169 | + "execution_count": 2, |
170 | 170 | "metadata": {}, |
171 | 171 | "output_type": "execute_result" |
172 | 172 | } |
|
358 | 358 | "metadata": {}, |
359 | 359 | "outputs": [], |
360 | 360 | "source": [ |
361 | | - "pd.set_option('display.float_format', '{:.2f}%'.format)" |
| 361 | + "pd.set_option('display.float_format', '{:.2%}'.format)\n", |
| 362 | + "\n", |
| 363 | + "# Note: By calling the statement, you will update Pandas default display settings \n", |
| 364 | + "# and apply to all float values. To reset it, you can call\n", |
| 365 | + "# pd.reset_option('display.float_format')" |
362 | 366 | ] |
363 | 367 | }, |
364 | 368 | { |
|
369 | 373 | { |
370 | 374 | "data": { |
371 | 375 | "text/plain": [ |
372 | | - "S 0.72%\n", |
373 | | - "C 0.19%\n", |
374 | | - "Q 0.09%\n", |
| 376 | + "S 72.44%\n", |
| 377 | + "C 18.90%\n", |
| 378 | + "Q 8.66%\n", |
375 | 379 | "Name: Embarked, dtype: float64" |
376 | 380 | ] |
377 | 381 | }, |
|
384 | 388 | "df['Embarked'].value_counts(normalize = True)" |
385 | 389 | ] |
386 | 390 | }, |
| 391 | + { |
| 392 | + "cell_type": "code", |
| 393 | + "execution_count": 11, |
| 394 | + "metadata": {}, |
| 395 | + "outputs": [], |
| 396 | + "source": [ |
| 397 | + "pd.reset_option('display.float_format')" |
| 398 | + ] |
| 399 | + }, |
| 400 | + { |
| 401 | + "cell_type": "code", |
| 402 | + "execution_count": 12, |
| 403 | + "metadata": {}, |
| 404 | + "outputs": [ |
| 405 | + { |
| 406 | + "data": { |
| 407 | + "text/html": [ |
| 408 | + "<style type=\"text/css\" >\n", |
| 409 | + "</style><table id=\"T_de79ef6a_0f55_11ec_8a56_acde48001122\" ><thead> <tr> <th class=\"blank level0\" ></th> <th class=\"col_heading level0 col0\" >Embarked</th> </tr></thead><tbody>\n", |
| 410 | + " <tr>\n", |
| 411 | + " <th id=\"T_de79ef6a_0f55_11ec_8a56_acde48001122level0_row0\" class=\"row_heading level0 row0\" >S</th>\n", |
| 412 | + " <td id=\"T_de79ef6a_0f55_11ec_8a56_acde48001122row0_col0\" class=\"data row0 col0\" >72.44%</td>\n", |
| 413 | + " </tr>\n", |
| 414 | + " <tr>\n", |
| 415 | + " <th id=\"T_de79ef6a_0f55_11ec_8a56_acde48001122level0_row1\" class=\"row_heading level0 row1\" >C</th>\n", |
| 416 | + " <td id=\"T_de79ef6a_0f55_11ec_8a56_acde48001122row1_col0\" class=\"data row1 col0\" >18.90%</td>\n", |
| 417 | + " </tr>\n", |
| 418 | + " <tr>\n", |
| 419 | + " <th id=\"T_de79ef6a_0f55_11ec_8a56_acde48001122level0_row2\" class=\"row_heading level0 row2\" >Q</th>\n", |
| 420 | + " <td id=\"T_de79ef6a_0f55_11ec_8a56_acde48001122row2_col0\" class=\"data row2 col0\" >8.66%</td>\n", |
| 421 | + " </tr>\n", |
| 422 | + " </tbody></table>" |
| 423 | + ], |
| 424 | + "text/plain": [ |
| 425 | + "<pandas.io.formats.style.Styler at 0x7fb2914f74d0>" |
| 426 | + ] |
| 427 | + }, |
| 428 | + "execution_count": 12, |
| 429 | + "metadata": {}, |
| 430 | + "output_type": "execute_result" |
| 431 | + } |
| 432 | + ], |
| 433 | + "source": [ |
| 434 | + "# Thanks for David B Rosen's advice (https://dabruro.medium.com/)\n", |
| 435 | + "#\n", |
| 436 | + "# Instead of Pandas display option, which would change the display of all float values, \n", |
| 437 | + "# you can can simply do this: \n", |
| 438 | + "df['Embarked'].value_counts(normalize = True).to_frame().style.format('{:.2%}')" |
| 439 | + ] |
| 440 | + }, |
387 | 441 | { |
388 | 442 | "cell_type": "markdown", |
389 | 443 | "metadata": {}, |
|
393 | 447 | }, |
394 | 448 | { |
395 | 449 | "cell_type": "code", |
396 | | - "execution_count": 7, |
| 450 | + "execution_count": 13, |
397 | 451 | "metadata": {}, |
398 | 452 | "outputs": [ |
399 | 453 | { |
|
405 | 459 | "Name: Fare, dtype: int64" |
406 | 460 | ] |
407 | 461 | }, |
408 | | - "execution_count": 7, |
| 462 | + "execution_count": 13, |
409 | 463 | "metadata": {}, |
410 | 464 | "output_type": "execute_result" |
411 | 465 | } |
|
416 | 470 | }, |
417 | 471 | { |
418 | 472 | "cell_type": "code", |
419 | | - "execution_count": 8, |
| 473 | + "execution_count": 14, |
420 | 474 | "metadata": {}, |
421 | 475 | "outputs": [ |
422 | 476 | { |
|
428 | 482 | "Name: Fare, dtype: int64" |
429 | 483 | ] |
430 | 484 | }, |
431 | | - "execution_count": 8, |
| 485 | + "execution_count": 14, |
432 | 486 | "metadata": {}, |
433 | 487 | "output_type": "execute_result" |
434 | 488 | } |
|
446 | 500 | }, |
447 | 501 | { |
448 | 502 | "cell_type": "code", |
449 | | - "execution_count": 21, |
| 503 | + "execution_count": 15, |
450 | 504 | "metadata": {}, |
451 | 505 | "outputs": [ |
452 | 506 | { |
|
462 | 516 | "Name: Sex, dtype: int64" |
463 | 517 | ] |
464 | 518 | }, |
465 | | - "execution_count": 21, |
| 519 | + "execution_count": 15, |
466 | 520 | "metadata": {}, |
467 | 521 | "output_type": "execute_result" |
468 | 522 | } |
|
480 | 534 | }, |
481 | 535 | { |
482 | 536 | "cell_type": "code", |
483 | | - "execution_count": 5, |
| 537 | + "execution_count": 16, |
484 | 538 | "metadata": {}, |
485 | 539 | "outputs": [ |
486 | 540 | { |
|
556 | 610 | " female 203" |
557 | 611 | ] |
558 | 612 | }, |
559 | | - "execution_count": 5, |
| 613 | + "execution_count": 16, |
560 | 614 | "metadata": {}, |
561 | 615 | "output_type": "execute_result" |
562 | 616 | } |
|
574 | 628 | }, |
575 | 629 | { |
576 | 630 | "cell_type": "code", |
577 | | - "execution_count": 6, |
| 631 | + "execution_count": 17, |
578 | 632 | "metadata": {}, |
579 | 633 | "outputs": [ |
580 | 634 | { |
|
635 | 689 | "ant 6 0" |
636 | 690 | ] |
637 | 691 | }, |
638 | | - "execution_count": 6, |
| 692 | + "execution_count": 17, |
639 | 693 | "metadata": {}, |
640 | 694 | "output_type": "execute_result" |
641 | 695 | } |
|
651 | 705 | }, |
652 | 706 | { |
653 | 707 | "cell_type": "code", |
654 | | - "execution_count": 7, |
| 708 | + "execution_count": 18, |
655 | 709 | "metadata": {}, |
656 | 710 | "outputs": [ |
657 | 711 | { |
|
664 | 718 | "dtype: int64" |
665 | 719 | ] |
666 | 720 | }, |
667 | | - "execution_count": 7, |
| 721 | + "execution_count": 18, |
668 | 722 | "metadata": {}, |
669 | 723 | "output_type": "execute_result" |
670 | 724 | } |
|
675 | 729 | }, |
676 | 730 | { |
677 | 731 | "cell_type": "code", |
678 | | - "execution_count": 8, |
| 732 | + "execution_count": 19, |
679 | 733 | "metadata": {}, |
680 | 734 | "outputs": [ |
681 | 735 | { |
|
736 | 790 | "2 2 1" |
737 | 791 | ] |
738 | 792 | }, |
739 | | - "execution_count": 8, |
| 793 | + "execution_count": 19, |
740 | 794 | "metadata": {}, |
741 | 795 | "output_type": "execute_result" |
742 | 796 | } |
|
0 commit comments