{ "metadata": { "name": "", "signature": "sha256:123d82ef0551f78e5dca94db6e00f1e10ae07d930467cf44709ccc6a9216776a" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "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", "collapsed": false, "input": [ "from IPython.display import display" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 7 }, { "cell_type": "heading", "level": 2, "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", "collapsed": false, "input": [ "import pandas" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here is a small amount of stock data for APPL:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%%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" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Writing data.csv\n" ] } ], "prompt_number": 10 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Read this as into a `DataFrame`:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "df = pandas.read_csv('data.csv')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "And view the HTML representation:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "df" ], "language": "python", "metadata": {}, "outputs": [ { "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", "