{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using a notebook\n", "The purpose of this notebook is to introduce the Jupyter interface. This notebook is a guide to the Jupyter interface and writing code and text in Jupyter notebooks with the _Python_ programming language and _Markdown_, the lightweight markup language.\n", "\n", "_This notebook was originally created for a Digital Mixer session at the [2016 STELLA Unconference](https://stellagroup.wordpress.com/)_" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Cells\n", "---\n", "The basic structure of a Jupyter notebook consists of linear sequence of cells from the top to the bottom of the page. A cell's content can consist of either:\n", "\n", "#### 1. code and code output" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0\n", "1\n", "2\n", "3\n", "4\n" ] } ], "source": [ "# create a range of numbers\n", "numbers = range(0, 5)\n", "# print out each of the numbers in the range\n", "for number in numbers:\n", " print(number)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 2. Markdown/html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### This is a big header written in markdown\n", "#### This is a medium header written in markdown\n", "##### This is a small header written in markdown\n", "This is a paragraph written in markdown\n", "

You can also write with html tags

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 3. raw text " ] }, { "cell_type": "raw", "metadata": {}, "source": [ "This is ugly. You probably don't need to use raw text." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Click on any text above to see what cell it belongs to. The active cell will be surrounded by a green or blue outline. A green outline indicates you are in edit mode for that cell and you can type in the cell. A blue outline indicates that you are in command mode and you cannot type in the active cell. **To enter edit mode in a cell click on any code input area or double-click on any rendered Markdown text.**\n", "\n", "Notice that you can see the content type of the active cell in the multi-choice button in the notebook toolbar at the top of the page:\n", "\n", "![alt text](./cellType.png)\n", "\n", "**You can also use this button to change the cell type.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Adding, removing, and moving cells\n", "---\n", "You can manage cells using the notebook toolbar.\n", "* **Adding a cell:** To add a new cell below the active cell, click \n", "* **Cut/copy/paste a cell:** Use to cut or to copy a cell and to paste the cut/copied cell below the active cell\n", "* **Move a cell:** To move the active cell up or down, click or \n", "* **Delete a cell:** To delete the active cell, click `Edit > Delete Cells`\n", "\n", "**Try adding a new Markdown cell and a Code cell, moving them around, and deleting them. _If you accidentally delete something you shouldn't have, you can undo it by going to:_** `Edit > Undo Delete Cells`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Running a cell\n", "---\n", "To run code in a cell or to render markdown as html in a cell you must _run_ the cell. \n", "\n", "**To run the contents of a cell:**\n", "1. activate it\n", "2. press `shift`+`return` _or_ click in the notebook toolbar at the top of the page.\n", "\n", "**Try running the three Python code cells below.** _You can edit and re-run a cell as many times as you want._" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# this is Python code -> RUN IT\n", "x = 2\n", "\n", "# the output of the last line of code is shown below the cell\n", "x * x" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# this is Python code -> RUN IT\n", "x = 2\n", "\n", "# you can also use the 'print' statement to print information to the output below the cell\n", "print(x)\n", "\n", "# the output of the last line of code is still shown below the cell\n", "x * x" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# this is Python code -> RUN IT\n", "x = 2\n", "\n", "# if there is an error in your code an error message will display in the output below the cell\n", "x + \"two\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Try editing and adding some text this Markdown cell**\n", "\n", "Double-click on **_this text_** to start\n", "\n", "_when you are done press `shift+return` to run_\n", "\n", "For an overview of Markdown format check out [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "More information on the UI\n", "---\n", "* In the notebook Menubar click `Help > User Interface Tour` for a quick, guided overview of the user interface.\n", "* Another overview of the interface from the Jupyter website: [Overview of the Notebook UI](http://nbviewer.jupyter.org/github/ipython/ipython/blob/3.x/examples/Notebook/Notebook%20Basics.ipynb#Overview-of-the-Notebook-UI)\n", "* More information on running code from the Jupyter website: [Running Code](http://nbviewer.jupyter.org/github/ipython/ipython/blob/3.x/examples/Notebook/Running%20Code.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Wrap up\n", "---\n", "You should have a basic understanding of how to navigate an interactive notebook, the cell types, how to manipulate cells (adding, moving, removing, etc.), and how to run cells.\n", "\n", "**Next:** For a basic overview of data analysis and visualization with pandas and matplotlib, download the following notebook and add it to your notebooks folder by uploading it in the Notebook dashboard: http://nbviewer.jupyter.org/github/WaltGurley/jupyter-notebooks-intro/blob/master/Jupyter%20-%20coding%20with%20Python.ipynb" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.1" } }, "nbformat": 4, "nbformat_minor": 0 }