In [3]:
from IPython.display import Image, FileLink, FileLinks, HTML
In [27]:
Image(filename='../profile_double11/static/custom/dongxi.jpg')
Out[27]:
In [5]:
FileLinks('.')
Out[5]:
In [6]:
FileLink('codemirror-python.ipynb')
Out[6]:
In [7]:
s = """<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>"""
HTML(s)
Out[7]:
In [ ]:
l = [1, 2, 3]
l
# 显示的是__repr__方法的返回值
In [28]:
import sqlite3
con = sqlite3.connect("baseball-archive-2012.sqlite")
df = pd.read_sql("select * from allstarfull limit 2", con)
In [29]:
df
Out[29]:
In [30]:
df._repr_html_() # pandas 已经添加了`_repr_html_`方法, 所以能显示
Out[30]:
In [9]:
s = '0 1n1 3\n2 5\n3 NaN\n4 6\n5 8\ndtype: float64'
In [10]:
s
Out[10]:
In [11]:
class A(object):
def __repr__(self):
return '0 1\n1 3\n2 5\n3 NaN\n4 6\n5 8\ndtype: float64'
In [12]:
a = A()
a
Out[12]:
In [ ]:
# http://ipython.org/ipython-doc/dev/config/integrating.htmls
# _repr_html_: return raw HTML as a string
# _repr_json_: return raw JSON as a string
# _repr_jpeg_: return raw JPEG data
# _repr_png_: return raw PNG data
# _repr_svg_: return raw SVG data as a string
# _repr_latex_: return LaTeX commands in a string surrounded by "$".
from IPython.display import (
display_html, display_jpeg, display_png,
display_javascript, display_svg, display_latex
)
In [ ]:
class DictTable(dict):
def _repr_html_(self):
html = ['<table>']
for key, value in self.iteritems():
html.append("<tr><td>{0}</td><td>{1}</td></tr>".format(key, value))
html.append("</table>")
return ''.join(html)
In [ ]:
t = DictTable(a=1, b=2, c=3)
In [ ]:
display_html(t)
In [ ]:
t