|
67 | 67 | "df = pd.DataFrame({'A': np.linspace(1, 10, 10)})\n",
|
68 | 68 | "df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],\n",
|
69 | 69 | " axis=1)\n",
|
| 70 | + "df.iloc[3, 3] = np.nan\n", |
70 | 71 | "df.iloc[0, 2] = np.nan"
|
71 | 72 | ]
|
72 | 73 | },
|
|
402 | 403 | "df.style.format({\"B\": lambda x: \"±{:.2f}\".format(abs(x))})"
|
403 | 404 | ]
|
404 | 405 | },
|
| 406 | + { |
| 407 | + "cell_type": "markdown", |
| 408 | + "metadata": {}, |
| 409 | + "source": [ |
| 410 | + "You can format the text displayed for missing values by `na_rep`." |
| 411 | + ] |
| 412 | + }, |
| 413 | + { |
| 414 | + "cell_type": "code", |
| 415 | + "execution_count": null, |
| 416 | + "metadata": {}, |
| 417 | + "outputs": [], |
| 418 | + "source": [ |
| 419 | + "df.style.format(\"{:.2%}\", na_rep=\"-\")" |
| 420 | + ] |
| 421 | + }, |
| 422 | + { |
| 423 | + "cell_type": "markdown", |
| 424 | + "metadata": {}, |
| 425 | + "source": [ |
| 426 | + "These formatting techniques can be used in combination with styling." |
| 427 | + ] |
| 428 | + }, |
| 429 | + { |
| 430 | + "cell_type": "code", |
| 431 | + "execution_count": null, |
| 432 | + "metadata": {}, |
| 433 | + "outputs": [], |
| 434 | + "source": [ |
| 435 | + "df.style.highlight_max().format(None, na_rep=\"-\")" |
| 436 | + ] |
| 437 | + }, |
405 | 438 | {
|
406 | 439 | "cell_type": "markdown",
|
407 | 440 | "metadata": {},
|
|
659 | 692 | "- precision\n",
|
660 | 693 | "- captions\n",
|
661 | 694 | "- table-wide styles\n",
|
| 695 | + "- missing values representation\n", |
662 | 696 | "- hiding the index or columns\n",
|
663 | 697 | "\n",
|
664 | 698 | "Each of these can be specified in two ways:\n",
|
|
800 | 834 | "We hope to collect some useful ones either in pandas, or preferable in a new package that [builds on top](#Extensibility) the tools here."
|
801 | 835 | ]
|
802 | 836 | },
|
| 837 | + { |
| 838 | + "cell_type": "markdown", |
| 839 | + "metadata": {}, |
| 840 | + "source": [ |
| 841 | + "### Missing values" |
| 842 | + ] |
| 843 | + }, |
| 844 | + { |
| 845 | + "cell_type": "markdown", |
| 846 | + "metadata": {}, |
| 847 | + "source": [ |
| 848 | + "You can control the default missing values representation for the entire table through `set_na_rep` method." |
| 849 | + ] |
| 850 | + }, |
| 851 | + { |
| 852 | + "cell_type": "code", |
| 853 | + "execution_count": null, |
| 854 | + "metadata": {}, |
| 855 | + "outputs": [], |
| 856 | + "source": [ |
| 857 | + "(df.style\n", |
| 858 | + " .set_na_rep(\"FAIL\")\n", |
| 859 | + " .format(None, na_rep=\"PASS\", subset=[\"D\"])\n", |
| 860 | + " .highlight_null(\"yellow\"))" |
| 861 | + ] |
| 862 | + }, |
803 | 863 | {
|
804 | 864 | "cell_type": "markdown",
|
805 | 865 | "metadata": {},
|
|
0 commit comments