Python dictionary as html table in ipython notebook

greole

Is there any (existing) way to display a python dictionary as html table in an ipython notebook. Say I have a dictionary

d = {'a': 2, 'b': 3}

then i run

magic_ipython_function(d)

to give me something like

enter image description here

Gurupad Hegde

You can write a custom function to override the default _repr_html_ function.

class DictTable(dict):
    # Overridden dict class which takes a dict in the form {'a': 2, 'b': 3},
    # and renders an HTML Table in IPython Notebook.
    def _repr_html_(self):
        html = ["<table width=100%>"]
        for key, value in self.iteritems():
            html.append("<tr>")
            html.append("<td>{0}</td>".format(key))
            html.append("<td>{0}</td>".format(value))
            html.append("</tr>")
        html.append("</table>")
        return ''.join(html)

Then, use it like:

DictTable(d)

Output will be: Sample Output of DictTable

If you are going to handle much bigger data (thousands of items), consider going with pandas.

Source of idea: Blog post of ListTable

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

IPython Notebook & Pandas: How does pandas produce html table?

From Dev

How to *not* display 'NaN' in ipython notebook (html table of pandas dataframe)?

From Dev

Printing 2 Python Pandas DataFrame in HTML Tables in iPython Notebook

From Java

Show DataFrame as table in iPython Notebook

From Dev

iPython Notebook not printing Dataframe as table

From Dev

Jupyter (IPython) notebook: Convert an HTML notebook to ipynb

From Dev

Import html to ipython notebook file

From Dev

ipython notebook align table to the left of cell

From Dev

Create a table containing pipes on ipython notebook

From Dev

How to Render Math Table Properly in IPython Notebook

From Dev

Ipython Notebook - Latex inside markdown table

From Dev

Converting ipython notebook to html with separate images

From Dev

CSS Styling of HTML in IPython Notebook output

From Dev

Displaying an HTML file with a JS inside an iPython notebook

From Dev

Parsing html table with BeautifulSoup to python dictionary

From Dev

Generate HTML Table from Python Dictionary

From Dev

List of dictionary in python as HTML Table format

From Dev

Parsing HTML table data using python dictionary

From Dev

Ipython notebook - Create a new notebook (Python conda or default Python)

From Dev

Execute IPython notebook cell from python script

From Dev

Ipython Notebook: Default Initialization Python Code

From Dev

ipython notebook R cell magic as a python function

From Dev

IPython Notebook in a virtualenv, using Python 3.3

From Dev

Anaconda: Python 3 and 2 in IPython/Jupyter Notebook

From Dev

Python Bloomberg API not connecting from ipython notebook

From Dev

Python Bloomberg API not connecting from ipython notebook

From Dev

Flask and HTML, from python dictionary to HTML table iteratively

From Dev

Passing parameters for TABLE_QUERY in Google Cloud Datalab iPython notebook

From Dev

In ipython notebook, can't hide table borders as usual

Related Related

  1. 1

    IPython Notebook & Pandas: How does pandas produce html table?

  2. 2

    How to *not* display 'NaN' in ipython notebook (html table of pandas dataframe)?

  3. 3

    Printing 2 Python Pandas DataFrame in HTML Tables in iPython Notebook

  4. 4

    Show DataFrame as table in iPython Notebook

  5. 5

    iPython Notebook not printing Dataframe as table

  6. 6

    Jupyter (IPython) notebook: Convert an HTML notebook to ipynb

  7. 7

    Import html to ipython notebook file

  8. 8

    ipython notebook align table to the left of cell

  9. 9

    Create a table containing pipes on ipython notebook

  10. 10

    How to Render Math Table Properly in IPython Notebook

  11. 11

    Ipython Notebook - Latex inside markdown table

  12. 12

    Converting ipython notebook to html with separate images

  13. 13

    CSS Styling of HTML in IPython Notebook output

  14. 14

    Displaying an HTML file with a JS inside an iPython notebook

  15. 15

    Parsing html table with BeautifulSoup to python dictionary

  16. 16

    Generate HTML Table from Python Dictionary

  17. 17

    List of dictionary in python as HTML Table format

  18. 18

    Parsing HTML table data using python dictionary

  19. 19

    Ipython notebook - Create a new notebook (Python conda or default Python)

  20. 20

    Execute IPython notebook cell from python script

  21. 21

    Ipython Notebook: Default Initialization Python Code

  22. 22

    ipython notebook R cell magic as a python function

  23. 23

    IPython Notebook in a virtualenv, using Python 3.3

  24. 24

    Anaconda: Python 3 and 2 in IPython/Jupyter Notebook

  25. 25

    Python Bloomberg API not connecting from ipython notebook

  26. 26

    Python Bloomberg API not connecting from ipython notebook

  27. 27

    Flask and HTML, from python dictionary to HTML table iteratively

  28. 28

    Passing parameters for TABLE_QUERY in Google Cloud Datalab iPython notebook

  29. 29

    In ipython notebook, can't hide table borders as usual

HotTag

Archive