Third Party Libraries With Rich Output¶
A number of third party libraries defined their own custom display logic. This gives their objects rich output by default when used in the Notebook.
from IPython.display import display
Pandas¶
Pandas is a data analysis library for Python. Its DataFrame
objects have an HTML table representation in the Notebook.
import pandas
Here is a small amount of stock data for APPL:
%%writefile data.csv
Date,Open,High,Low,Close,Volume,Adj Close
2012-06-01,569.16,590.00,548.50,584.00,14077000,581.50
2012-05-01,584.90,596.76,522.18,577.73,18827900,575.26
2012-04-02,601.83,644.00,555.00,583.98,28759100,581.48
2012-03-01,548.17,621.45,516.22,599.55,26486000,596.99
2012-02-01,458.41,547.61,453.98,542.44,22001000,540.12
2012-01-03,409.40,458.24,409.00,456.48,12949100,454.53
Read this as into a DataFrame
:
df = pandas.read_csv('data.csv')
And view the HTML representation:
df
SymPy¶
SymPy is a symbolic computing library for Python. Its equation objects have LaTeX representations that are rendered in the Notebook.
from sympy.interactive.printing import init_printing
init_printing(use_latex='mathjax')
from __future__ import division
import sympy as sym
from sympy import *
x, y, z = symbols("x y z")
k, m, n = symbols("k m n", integer=True)
f, g, h = map(Function, 'fgh')
Rational(3,2)*pi + exp(I*x) / (x**2 + y)
a = 1/x + (x*sin(x) - 1)/x
a
(1/cos(x)).series(x, 0, 6)
Vincent¶
Vincent is a visualization library that uses the Vega visualization grammar to build d3.js based visualizations in the Notebook and on http://nbviewer.ipython.org. Visualization
objects in Vincetn have rich HTML and JavaSrcript representations.
import vincent
import pandas as pd
import pandas.io.data as web
import datetime
all_data = {}
date_start = datetime.datetime(2010, 1, 1)
date_end = datetime.datetime(2014, 1, 1)
for ticker in ['AAPL', 'IBM', 'YHOO', 'MSFT']:
all_data[ticker] = web.DataReader(ticker, 'yahoo', date_start, date_end)
price = pd.DataFrame({tic: data['Adj Close']
for tic, data in all_data.items()})
vincent.initialize_notebook()
line = vincent.Line(price[['AAPL', 'IBM', 'YHOO', 'MSFT']], width=600, height=300)
line.axis_titles(x='Date', y='Price')
line.legend(title='Ticker')
display(line)