Created
September 27, 2017 17:04
-
-
Save shreddd/77c4cf24821db86741a3543312a4670b to your computer and use it in GitHub Desktop.
Render a dictionary as an HTML table via pandas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 28, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "d={u'2012-06-08': 388,\n", | |
| " u'2012-06-09': 388,\n", | |
| " u'2012-06-10': 388,\n", | |
| " u'2012-06-11': 389,\n", | |
| " u'2012-06-12': 389,\n", | |
| " u'2012-06-13': 389,\n", | |
| " u'2012-06-14': 389,\n", | |
| " u'2012-06-15': 389,\n", | |
| " u'2012-06-16': 389,\n", | |
| " u'2012-06-17': 389,\n", | |
| " u'2012-06-18': 390,\n", | |
| " u'2012-06-19': 390,\n", | |
| " u'2012-06-20': 390,\n", | |
| " u'2012-06-21': 390,\n", | |
| " u'2012-06-22': 390,\n", | |
| " u'2012-06-23': 390,\n", | |
| " u'2012-06-24': 390,\n", | |
| " u'2012-06-25': 391,\n", | |
| " u'2012-06-26': 391,\n", | |
| " u'2012-06-27': 391,\n", | |
| " u'2012-06-28': 391,\n", | |
| " u'2012-06-29': 391,\n", | |
| " u'2012-06-30': 391,\n", | |
| " u'2012-07-01': 391,\n", | |
| " u'2012-07-02': 392,\n", | |
| " u'2012-07-03': 392,\n", | |
| " u'2012-07-04': 392,\n", | |
| " u'2012-07-05': 392,\n", | |
| " u'2012-07-06': 392}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 30, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "df = pd.DataFrame(list(d.items()), columns=['Date', 'Value'])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 31, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from IPython.display import display" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 32, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th>Date</th>\n", | |
| " <th>Value</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0</th>\n", | |
| " <td>2012-06-26</td>\n", | |
| " <td>391</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>1</th>\n", | |
| " <td>2012-06-24</td>\n", | |
| " <td>390</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>2</th>\n", | |
| " <td>2012-06-12</td>\n", | |
| " <td>389</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>3</th>\n", | |
| " <td>2012-06-18</td>\n", | |
| " <td>390</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>4</th>\n", | |
| " <td>2012-06-09</td>\n", | |
| " <td>388</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>5</th>\n", | |
| " <td>2012-06-23</td>\n", | |
| " <td>390</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>6</th>\n", | |
| " <td>2012-06-11</td>\n", | |
| " <td>389</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>7</th>\n", | |
| " <td>2012-06-21</td>\n", | |
| " <td>390</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>8</th>\n", | |
| " <td>2012-06-13</td>\n", | |
| " <td>389</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>9</th>\n", | |
| " <td>2012-07-05</td>\n", | |
| " <td>392</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>10</th>\n", | |
| " <td>2012-07-03</td>\n", | |
| " <td>392</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>11</th>\n", | |
| " <td>2012-06-22</td>\n", | |
| " <td>390</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>12</th>\n", | |
| " <td>2012-06-30</td>\n", | |
| " <td>391</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>13</th>\n", | |
| " <td>2012-06-16</td>\n", | |
| " <td>389</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>14</th>\n", | |
| " <td>2012-06-20</td>\n", | |
| " <td>390</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>15</th>\n", | |
| " <td>2012-06-19</td>\n", | |
| " <td>390</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>16</th>\n", | |
| " <td>2012-06-15</td>\n", | |
| " <td>389</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>17</th>\n", | |
| " <td>2012-07-04</td>\n", | |
| " <td>392</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>18</th>\n", | |
| " <td>2012-07-06</td>\n", | |
| " <td>392</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>19</th>\n", | |
| " <td>2012-06-10</td>\n", | |
| " <td>388</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>20</th>\n", | |
| " <td>2012-06-14</td>\n", | |
| " <td>389</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>21</th>\n", | |
| " <td>2012-07-01</td>\n", | |
| " <td>391</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>22</th>\n", | |
| " <td>2012-06-17</td>\n", | |
| " <td>389</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>23</th>\n", | |
| " <td>2012-06-29</td>\n", | |
| " <td>391</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>24</th>\n", | |
| " <td>2012-06-27</td>\n", | |
| " <td>391</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>25</th>\n", | |
| " <td>2012-07-02</td>\n", | |
| " <td>392</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>26</th>\n", | |
| " <td>2012-06-28</td>\n", | |
| " <td>391</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>27</th>\n", | |
| " <td>2012-06-08</td>\n", | |
| " <td>388</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>28</th>\n", | |
| " <td>2012-06-25</td>\n", | |
| " <td>391</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " Date Value\n", | |
| "0 2012-06-26 391\n", | |
| "1 2012-06-24 390\n", | |
| "2 2012-06-12 389\n", | |
| "3 2012-06-18 390\n", | |
| "4 2012-06-09 388\n", | |
| "5 2012-06-23 390\n", | |
| "6 2012-06-11 389\n", | |
| "7 2012-06-21 390\n", | |
| "8 2012-06-13 389\n", | |
| "9 2012-07-05 392\n", | |
| "10 2012-07-03 392\n", | |
| "11 2012-06-22 390\n", | |
| "12 2012-06-30 391\n", | |
| "13 2012-06-16 389\n", | |
| "14 2012-06-20 390\n", | |
| "15 2012-06-19 390\n", | |
| "16 2012-06-15 389\n", | |
| "17 2012-07-04 392\n", | |
| "18 2012-07-06 392\n", | |
| "19 2012-06-10 388\n", | |
| "20 2012-06-14 389\n", | |
| "21 2012-07-01 391\n", | |
| "22 2012-06-17 389\n", | |
| "23 2012-06-29 391\n", | |
| "24 2012-06-27 391\n", | |
| "25 2012-07-02 392\n", | |
| "26 2012-06-28 391\n", | |
| "27 2012-06-08 388\n", | |
| "28 2012-06-25 391" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "display(df)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Anaconda3", | |
| "language": "python", | |
| "name": "anaconda3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.5.2" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment