|
674 | 674 | "- precision\n",
|
675 | 675 | "- captions\n",
|
676 | 676 | "- table-wide styles\n",
|
| 677 | + "- hiding the index or columns\n", |
677 | 678 | "\n",
|
678 | 679 | "Each of these can be specified in two ways:\n",
|
679 | 680 | "\n",
|
680 | 681 | "- A keyword argument to `Styler.__init__`\n",
|
681 |
| - "- A call to one of the `.set_` methods, e.g. `.set_caption`\n", |
| 682 | + "- A call to one of the `.set_` or `.hide_` methods, e.g. `.set_caption` or `.hide_columns`\n", |
682 | 683 | "\n",
|
683 |
| - "The best method to use depends on the context. Use the `Styler` constructor when building many styled DataFrames that should all share the same properties. For interactive use, the`.set_` methods are more convenient." |
| 684 | + "The best method to use depends on the context. Use the `Styler` constructor when building many styled DataFrames that should all share the same properties. For interactive use, the`.set_` and `.hide_` methods are more convenient." |
684 | 685 | ]
|
685 | 686 | },
|
686 | 687 | {
|
|
814 | 815 | "We hope to collect some useful ones either in pandas, or preferable in a new package that [builds on top](#Extensibility) the tools here."
|
815 | 816 | ]
|
816 | 817 | },
|
| 818 | + { |
| 819 | + "cell_type": "markdown", |
| 820 | + "metadata": {}, |
| 821 | + "source": [ |
| 822 | + "### Hiding the Index or Columns" |
| 823 | + ] |
| 824 | + }, |
| 825 | + { |
| 826 | + "cell_type": "markdown", |
| 827 | + "metadata": {}, |
| 828 | + "source": [ |
| 829 | + "The index can be hidden from rendering by calling `Styler.hide_index`. Columns can be hidden from rendering by calling `Styler.hide_columns` and passing in the name of a column, or a slice of columns." |
| 830 | + ] |
| 831 | + }, |
| 832 | + { |
| 833 | + "cell_type": "code", |
| 834 | + "execution_count": null, |
| 835 | + "metadata": {}, |
| 836 | + "outputs": [], |
| 837 | + "source": [ |
| 838 | + "df.style.hide_index()" |
| 839 | + ] |
| 840 | + }, |
| 841 | + { |
| 842 | + "cell_type": "code", |
| 843 | + "execution_count": null, |
| 844 | + "metadata": {}, |
| 845 | + "outputs": [], |
| 846 | + "source": [ |
| 847 | + "df.style.hide_columns(['C','D'])" |
| 848 | + ] |
| 849 | + }, |
817 | 850 | {
|
818 | 851 | "cell_type": "markdown",
|
819 | 852 | "metadata": {},
|
|
875 | 908 | {
|
876 | 909 | "cell_type": "code",
|
877 | 910 | "execution_count": null,
|
878 |
| - "metadata": {}, |
| 911 | + "metadata": { |
| 912 | + "collapsed": true |
| 913 | + }, |
879 | 914 | "outputs": [],
|
880 | 915 | "source": [
|
881 | 916 | "from IPython.html import widgets\n",
|
|
911 | 946 | {
|
912 | 947 | "cell_type": "code",
|
913 | 948 | "execution_count": null,
|
914 |
| - "metadata": {}, |
| 949 | + "metadata": { |
| 950 | + "collapsed": true |
| 951 | + }, |
915 | 952 | "outputs": [],
|
916 | 953 | "source": [
|
917 | 954 | "np.random.seed(25)\n",
|
|
1010 | 1047 | {
|
1011 | 1048 | "cell_type": "code",
|
1012 | 1049 | "execution_count": null,
|
1013 |
| - "metadata": {}, |
| 1050 | + "metadata": { |
| 1051 | + "collapsed": true |
| 1052 | + }, |
1014 | 1053 | "outputs": [],
|
1015 | 1054 | "source": [
|
1016 | 1055 | "%mkdir templates"
|
|
1027 | 1066 | {
|
1028 | 1067 | "cell_type": "code",
|
1029 | 1068 | "execution_count": null,
|
1030 |
| - "metadata": {}, |
| 1069 | + "metadata": { |
| 1070 | + "collapsed": true |
| 1071 | + }, |
1031 | 1072 | "outputs": [],
|
1032 | 1073 | "source": [
|
1033 | 1074 | "%%file templates/myhtml.tpl\n",
|
|
1078 | 1119 | {
|
1079 | 1120 | "cell_type": "code",
|
1080 | 1121 | "execution_count": null,
|
1081 |
| - "metadata": {}, |
| 1122 | + "metadata": { |
| 1123 | + "collapsed": true |
| 1124 | + }, |
1082 | 1125 | "outputs": [],
|
1083 | 1126 | "source": [
|
1084 | 1127 | "MyStyler(df)"
|
|
1094 | 1137 | {
|
1095 | 1138 | "cell_type": "code",
|
1096 | 1139 | "execution_count": null,
|
1097 |
| - "metadata": {}, |
| 1140 | + "metadata": { |
| 1141 | + "collapsed": true |
| 1142 | + }, |
1098 | 1143 | "outputs": [],
|
1099 | 1144 | "source": [
|
1100 | 1145 | "HTML(MyStyler(df).render(table_title=\"Extending Example\"))"
|
|
1110 | 1155 | {
|
1111 | 1156 | "cell_type": "code",
|
1112 | 1157 | "execution_count": null,
|
1113 |
| - "metadata": {}, |
| 1158 | + "metadata": { |
| 1159 | + "collapsed": true |
| 1160 | + }, |
1114 | 1161 | "outputs": [],
|
1115 | 1162 | "source": [
|
1116 | 1163 | "EasyStyler = Styler.from_custom_template(\"templates\", \"myhtml.tpl\")\n",
|
|
1127 | 1174 | {
|
1128 | 1175 | "cell_type": "code",
|
1129 | 1176 | "execution_count": null,
|
1130 |
| - "metadata": {}, |
| 1177 | + "metadata": { |
| 1178 | + "collapsed": true |
| 1179 | + }, |
1131 | 1180 | "outputs": [],
|
1132 | 1181 | "source": [
|
1133 | 1182 | "with open(\"template_structure.html\") as f:\n",
|
|
1147 | 1196 | "cell_type": "code",
|
1148 | 1197 | "execution_count": null,
|
1149 | 1198 | "metadata": {
|
| 1199 | + "collapsed": true, |
1150 | 1200 | "nbsphinx": "hidden"
|
1151 | 1201 | },
|
1152 | 1202 | "outputs": [],
|
|
1163 | 1213 | ],
|
1164 | 1214 | "metadata": {
|
1165 | 1215 | "kernelspec": {
|
1166 |
| - "display_name": "Python 3", |
| 1216 | + "display_name": "Python [default]", |
1167 | 1217 | "language": "python",
|
1168 | 1218 | "name": "python3"
|
1169 | 1219 | },
|
|
1177 | 1227 | "name": "python",
|
1178 | 1228 | "nbconvert_exporter": "python",
|
1179 | 1229 | "pygments_lexer": "ipython3",
|
1180 |
| - "version": "3.6.1" |
| 1230 | + "version": "3.5.3" |
| 1231 | + }, |
| 1232 | + "widgets": { |
| 1233 | + "application/vnd.jupyter.widget-state+json": { |
| 1234 | + "state": {}, |
| 1235 | + "version_major": 1, |
| 1236 | + "version_minor": 0 |
| 1237 | + } |
1181 | 1238 | }
|
1182 | 1239 | },
|
1183 | 1240 | "nbformat": 4,
|
|
0 commit comments