{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Third Party Libraries With Rich Output" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from IPython.display import display" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pandas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Pandas](http://pandas.pydata.org/) is a data analysis library for Python. Its `DataFrame` objects have an HTML table representation in the Notebook." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pandas" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a small amount of stock data for APPL:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing data.csv\n" ] } ], "source": [ "%%writefile data.csv\n", "Date,Open,High,Low,Close,Volume,Adj Close\n", "2012-06-01,569.16,590.00,548.50,584.00,14077000,581.50\n", "2012-05-01,584.90,596.76,522.18,577.73,18827900,575.26\n", "2012-04-02,601.83,644.00,555.00,583.98,28759100,581.48\n", "2012-03-01,548.17,621.45,516.22,599.55,26486000,596.99\n", "2012-02-01,458.41,547.61,453.98,542.44,22001000,540.12\n", "2012-01-03,409.40,458.24,409.00,456.48,12949100,454.53" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Read this as into a `DataFrame`:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [], "source": [ "df = pandas.read_csv('data.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And view the HTML representation:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | Date | \n", "Open | \n", "High | \n", "Low | \n", "Close | \n", "Volume | \n", "Adj Close | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "2012-06-01 | \n", "569.16 | \n", "590.00 | \n", "548.50 | \n", "584.00 | \n", "14077000 | \n", "581.50 | \n", "
1 | \n", "2012-05-01 | \n", "584.90 | \n", "596.76 | \n", "522.18 | \n", "577.73 | \n", "18827900 | \n", "575.26 | \n", "
2 | \n", "2012-04-02 | \n", "601.83 | \n", "644.00 | \n", "555.00 | \n", "583.98 | \n", "28759100 | \n", "581.48 | \n", "
3 | \n", "2012-03-01 | \n", "548.17 | \n", "621.45 | \n", "516.22 | \n", "599.55 | \n", "26486000 | \n", "596.99 | \n", "
4 | \n", "2012-02-01 | \n", "458.41 | \n", "547.61 | \n", "453.98 | \n", "542.44 | \n", "22001000 | \n", "540.12 | \n", "
5 | \n", "2012-01-03 | \n", "409.40 | \n", "458.24 | \n", "409.00 | \n", "456.48 | \n", "12949100 | \n", "454.53 | \n", "
6 rows \u00d7 7 columns
\n", "