{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Jupyter Quickstart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This document is a short introduction to the basic features of the Jupyter notebook. As you read along, you will make changes to this document to explore Jupyter's features." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What is Jupyter?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Jupyter is an application that runs on your web browser, and lets you create **Jupyter Notebooks** (like this one). Notebooks are a collection of *cells*. Cells can contain:\n", "\n", "1. Live (runnable) code, and\n", "2. Explanatory text written using the Markdown markup language\n", "3. Mathematical equations and inline expressions using LaTeX" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To edit a cell, simply double-click on it. Once you're done making changes, press `Shift+Enter` or press the button on the cell toolbar above. Double click on the equation below to see the LaTeX code that is used to generate it. Make a small change to the equation and then execute the cell; for example, change the `2` to a `5`:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$ E = mc^2 $$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below is an example of a *code cell*, which contains Python code to print some words. Try and run it:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello World!\n" ] } ], "source": [ "print(\"Hello World!\")" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "As you can see, the output of any cell is presented below the cell. You can edit a code cell, and re-run it to change the output - try to get this cell to print \"Goodbye World!\" instead.\n", "\n", "The above cell produces text output, but the output can be an image, an animation, a table, or an HTML \"widget\" that lets you interact with your data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A simple example: working with small data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the cells that follow, we will read some data from a file called `animals.txt` and plot it using Python. If you don't know Python - that's OK. You will only be making small changes to the code.\n", "\n", "The cell below creates the file.\n", "The line\n", "\n", " %%writefile animals.txt\n", "\n", "at the top of the cell instructs the notebook to save the contents of the cell to a file called `animals.txt`.\n", "The file will be created in the same directory (folder) as this notebook." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing animals.txt\n" ] } ], "source": [ "%%writefile animals.txt\n", "2011-04-22 12:49 Grizzly 4\n", "2011-04-22 10:59 Grizzly 20\n", "2011-04-23 20:41 Muskox 36\n", "2011-04-24 02:04 Fox 31\n", "2011-04-25 10:54 Grizzly 20\n", "2011-04-25 02:45 Muskox 15\n", "2011-04-26 09:38 Owl 25\n", "2011-04-26 09:42 Wolf 40\n", "2011-04-26 10:04 Elk 21\n", "2011-04-26 09:42 Owl 3\n", "2011-04-26 14:01 Owl 5\n", "2011-04-27 23:40 Owl 5\n", "2011-04-27 16:22 Ptarmigan 13\n", "2011-04-28 16:32 Muskox 1\n", "2011-04-28 01:05 Grizzly 27\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The cell below reads the file `animals.txt`, and displays its contents as a table.\n", "This data corresponds to animal sightings made at different times\n", "and at different sites.\n", "Run the cell to see the table." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", " | Date | \n", "Time | \n", "Animal | \n", "Site ID | \n", "
---|---|---|---|---|
0 | \n", "2011-04-22 | \n", "12:49 | \n", "Grizzly | \n", "4 | \n", "
1 | \n", "2011-04-22 | \n", "10:59 | \n", "Grizzly | \n", "20 | \n", "
2 | \n", "2011-04-23 | \n", "20:41 | \n", "Muskox | \n", "36 | \n", "
3 | \n", "2011-04-24 | \n", "02:04 | \n", "Fox | \n", "31 | \n", "
4 | \n", "2011-04-25 | \n", "10:54 | \n", "Grizzly | \n", "20 | \n", "
5 | \n", "2011-04-25 | \n", "02:45 | \n", "Muskox | \n", "15 | \n", "
6 | \n", "2011-04-26 | \n", "09:38 | \n", "Owl | \n", "25 | \n", "
7 | \n", "2011-04-26 | \n", "09:42 | \n", "Wolf | \n", "40 | \n", "
8 | \n", "2011-04-26 | \n", "10:04 | \n", "Elk | \n", "21 | \n", "
9 | \n", "2011-04-26 | \n", "09:42 | \n", "Owl | \n", "3 | \n", "
10 | \n", "2011-04-26 | \n", "14:01 | \n", "Owl | \n", "5 | \n", "
11 | \n", "2011-04-27 | \n", "23:40 | \n", "Owl | \n", "5 | \n", "
12 | \n", "2011-04-27 | \n", "16:22 | \n", "Ptarmigan | \n", "13 | \n", "
13 | \n", "2011-04-28 | \n", "16:32 | \n", "Muskox | \n", "1 | \n", "
14 | \n", "2011-04-28 | \n", "01:05 | \n", "Grizzly | \n", "27 | \n", "