From 753c4e09307b520b2819b688b1d390b1825110f7 Mon Sep 17 00:00:00 2001 From: Brandon Rhodes Date: Sat, 28 Mar 2015 01:21:38 -0400 Subject: [PATCH] Get Pandas tables minimally styled --- Diagrams.ipynb | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- style-table.css | 24 +++++++--- tmp.dot | 10 ++-- 3 files changed, 159 insertions(+), 15 deletions(-) diff --git a/Diagrams.ipynb b/Diagrams.ipynb index 9f02a07..d183509 100644 --- a/Diagrams.ipynb +++ b/Diagrams.ipynb @@ -22,6 +22,62 @@ }, { "cell_type": "code", + "execution_count": 164, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 164, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from IPython.core.display import HTML\n", + "HTML(''.format(open('style-table.css').read()))" + ] + }, + { + "cell_type": "code", "execution_count": 57, "metadata": { "collapsed": false @@ -614,7 +670,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 161, "metadata": { "collapsed": false }, @@ -681,7 +737,7 @@ "Howard Hawks 4 His Girl Friday 1940" ] }, - "execution_count": 31, + "execution_count": 161, "metadata": {}, "output_type": "execute_result" } @@ -1758,6 +1814,77 @@ }, { "cell_type": "code", + "execution_count": 154, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\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", + " \n", + " \n", + " \n", + " \n", + "
year
directortitle
Alfred HitchcockNorth by Northwest 1959
Notorious 1946
To Catch a Thief 1955
George CukorThe Philadelphia Story 1940
Howard HawksHis Girl Friday 1940
\n", + "
" + ], + "text/plain": [ + " year\n", + "director title \n", + "Alfred Hitchcock North by Northwest 1959\n", + " Notorious 1946\n", + " To Catch a Thief 1955\n", + "George Cukor The Philadelphia Story 1940\n", + "Howard Hawks His Girl Friday 1940" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df1.groupby(['director', 'title']).first()" + ] + }, + { + "cell_type": "code", "execution_count": 134, "metadata": { "collapsed": false @@ -1829,7 +1956,7 @@ }, { "cell_type": "code", - "execution_count": 147, + "execution_count": 150, "metadata": { "collapsed": false }, @@ -1840,14 +1967,15 @@ "812" ] }, - "execution_count": 147, + "execution_count": 150, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "open('_tyd.html', 'w').write(df1.to_html())\n", - "open('d_ty.html', 'w').write(df1.set_index('director').to_html())" + "open('u__tyd.html', 'w').write(df1.to_html())\n", + "open('u_d_ty.html', 'w').write(df1.set_index('director').to_html())\n", + "open('s_d_ty.html', 'w').write(df1.set_index('director').sort_index().to_html())" ] }, { diff --git a/style-table.css b/style-table.css index cd21334..575cd88 100644 --- a/style-table.css +++ b/style-table.css @@ -1,18 +1,30 @@ body { margin: 0; - color: blue; font-family: Helvetica; } -table { +table.dataframe { border-collapse: collapse; border: none; } -td, th { +table.dataframe tr { border: none; +} +table.dataframe td, table.dataframe th { margin: 0; - padding-left: 0.5em; + border: 1px solid white; + padding-left: 0.25em; + padding-right: 0.25em; } -th { +table.dataframe th:not(:empty) { + background-color: #fec; text-align: left; - color: red; + font-weight: normal; +} +table.dataframe tr:nth-child(2) th:empty { + border-left: none; + border-right: 1px dashed #888; +} +table.dataframe td { + border: 2px solid #ccf; + background-color: #f4f4ff; } diff --git a/tmp.dot b/tmp.dot index db3e884..65db435 100644 --- a/tmp.dot +++ b/tmp.dot @@ -3,9 +3,13 @@ digraph { node [label=""] edge [fontname="Ubuntu Light"; fontsize=12.0] -_tyd [shape=none image="_tyd.png"]; -d_ty [shape=none image="d_ty.png"]; +u__tyd [shape=none image="u__tyd.png"]; +u_d_ty [shape=none image="u_d_ty.png"]; +s_d_ty [shape=none image="s_d_ty.png"]; -_tyd -> d_ty [label=" .set_index('director')"]; +u__tyd -> u_d_ty [label=" .set_index('director')"]; +u_d_ty -> s_d_ty [label=" .sort_index()"]; + +u__tyd -> s_d_ty [label=" .set_index('director')"]; } \ No newline at end of file