Permalink
Browse files

Get Pandas tables minimally styled

  • Loading branch information...
1 parent c7bc37f commit 753c4e09307b520b2819b688b1d390b1825110f7 @brandon-rhodes committed Mar 28, 2015
Showing with 159 additions and 15 deletions.
  1. +134 −6 Diagrams.ipynb
  2. +18 −6 style-table.css
  3. +7 −3 tmp.dot
View
@@ -22,6 +22,62 @@
},
{
"cell_type": "code",
+ "execution_count": 164,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<style>body {\n",
+ " margin: 0;\n",
+ " font-family: Helvetica;\n",
+ "}\n",
+ "table.dataframe {\n",
+ " border-collapse: collapse;\n",
+ " border: none;\n",
+ "}\n",
+ "table.dataframe tr {\n",
+ " border: none;\n",
+ "}\n",
+ "table.dataframe td, table.dataframe th {\n",
+ " margin: 0;\n",
+ " border: 1px solid white;\n",
+ " padding-left: 0.25em;\n",
+ " padding-right: 0.25em;\n",
+ "}\n",
+ "table.dataframe th:not(:empty) {\n",
+ " background-color: #fec;\n",
+ " text-align: left;\n",
+ " font-weight: normal;\n",
+ "}\n",
+ "table.dataframe tr:nth-child(2) th:empty {\n",
+ " border-left: none;\n",
+ " border-right: 1px dashed #888;\n",
+ "}\n",
+ "table.dataframe td {\n",
+ " border: 2px solid #ccf;\n",
+ " background-color: #f4f4ff;\n",
+ "}\n",
+ "</style>"
+ ],
+ "text/plain": [
+ "<IPython.core.display.HTML object>"
+ ]
+ },
+ "execution_count": 164,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "from IPython.core.display import HTML\n",
+ "HTML('<style>{}</style>'.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": [
+ "<div style=\"max-height:1000px;max-width:1500px;overflow:auto;\">\n",
+ "<table border=\"1\" class=\"dataframe\">\n",
+ " <thead>\n",
+ " <tr style=\"text-align: right;\">\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th>year</th>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>director</th>\n",
+ " <th>title</th>\n",
+ " <th></th>\n",
+ " </tr>\n",
+ " </thead>\n",
+ " <tbody>\n",
+ " <tr>\n",
+ " <th rowspan=\"3\" valign=\"top\">Alfred Hitchcock</th>\n",
+ " <th>North by Northwest</th>\n",
+ " <td> 1959</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>Notorious</th>\n",
+ " <td> 1946</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>To Catch a Thief</th>\n",
+ " <td> 1955</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>George Cukor</th>\n",
+ " <th>The Philadelphia Story</th>\n",
+ " <td> 1940</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>Howard Hawks</th>\n",
+ " <th>His Girl Friday</th>\n",
+ " <td> 1940</td>\n",
+ " </tr>\n",
+ " </tbody>\n",
+ "</table>\n",
+ "</div>"
+ ],
+ "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())"
]
},
{
View
@@ -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;
}
View
10 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')"];
}

0 comments on commit 753c4e0

Please sign in to comment.