#!/usr/bin/env python # coding: utf-8 # # Third Party Libraries With Rich Output # A number of third party libraries defined their own custom display logic. This gives their objcts rich output by default when used in the Notebook. # In[1]: from IPython.display import display # ## Pandas # [Pandas](http://pandas.pydata.org/) is a data analysis library for Python. Its `DataFrame` objects have an HTML table representation in the Notebook. # In[2]: import pandas # Here is a small amount of stock data for APPL: # In[3]: get_ipython().run_cell_magic('writefile', 'data.csv', 'Date,Open,High,Low,Close,Volume,Adj Close\n2012-06-01,569.16,590.00,548.50,584.00,14077000,581.50\n2012-05-01,584.90,596.76,522.18,577.73,18827900,575.26\n2012-04-02,601.83,644.00,555.00,583.98,28759100,581.48\n2012-03-01,548.17,621.45,516.22,599.55,26486000,596.99\n2012-02-01,458.41,547.61,453.98,542.44,22001000,540.12\n2012-01-03,409.40,458.24,409.00,456.48,12949100,454.53\n') # Read this as into a `DataFrame`: # In[4]: df = pandas.read_csv('data.csv') # And view the HTML representation: # In[5]: df # ## SymPy # [SymPy](http://sympy.org/) is a symbolic computing library for Python. Its equation objects have LaTeX representations that are rendered in the Notebook. # In[6]: from sympy.interactive.printing import init_printing init_printing(use_latex='mathjax') # In[7]: 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') # In[8]: Rational(3,2)*pi + exp(I*x) / (x**2 + y) # In[9]: a = 1/x + (x*sin(x) - 1)/x a # In[10]: (1/cos(x)).series(x, 0, 6) # ## Vincent # [Vincent](https://vincent.readthedocs.org/en/latest/) is a visualization library that uses the [Vega](http://trifacta.github.io/vega/) visualization grammar to build [d3.js](http://d3js.org/) based visualizations in the Notebook and on http://nbviewer.ipython.org. `Visualization` objects in Vincetn have rich HTML and JavaSrcript representations. # In[11]: import vincent import pandas as pd # In[12]: 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()}) # In[13]: vincent.initialize_notebook() # In[14]: 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)