Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Python 3.7 #71

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 313 additions & 1 deletion cookbook/A quick tour of IPython Notebook.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1,313 @@
{"nbformat": 4, "metadata": {"orig_nbformat": 3}, "cells": [{"source": "# A quick tour of IPython Notebook", "cell_type": "markdown", "metadata": {}}, {"source": "This tour will work a little better in interactive mode, so it'll be better if you get IPython notebook installed and running. You can start it from a terminal by running\n\n`ipython notebook`", "cell_type": "markdown", "metadata": {}}, {"source": "First, we need to explain how to run cells. Try to run the cell below!", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "import pandas as pd\n\nprint \"Hi! This is a cell. Press the \u25b6 button above to run it\"", "metadata": {"collapsed": false, "trusted": false}}, {"source": "You can also run a cell with Ctrl+Enter or Shift+Enter. Experiment a bit with that.", "cell_type": "markdown", "metadata": {}}, {"source": "One of the most useful things about IPython notebook is its tab completion. \n\nTry this: click just after read_csv( in the cell below and press Shift+Tab (or Tab if you're using IPython 1.x) 4 times, slowly", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "pd.read_csv(", "metadata": {"collapsed": false, "trusted": false}}, {"source": "After the first time, you should see this:\n<div align=\"center\">\n<img src=\"files/images/tab-once.png\" width=\"75%\">\n</div>\n\nAfter the second time:\n<div align=\"center\">\n<img src=\"files/images/tab-twice.png\" width=\"75%\">\n</div>\n\nAfter the fourth time, a big help box should pop up at the bottom of the screen, with the full documentation for the `read_csv` function:\n<div align=\"center\">\n<img src=\"files/images/tab-4-times.png\" width=\"90%\">\n</div>", "cell_type": "markdown", "metadata": {}}, {"source": "I find this amazingly useful. I think of this as \"the more confused I am, the more times I should press Shift+Tab\". Nothing bad will happen if you tab complete 12 times.\n\nOkay, let's try tab completion for function names!", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": null, "outputs": [], "source": "pd.r", "metadata": {"collapsed": false, "trusted": false}}, {"source": "You should see this:\n\n<div align=\"center\">\n<img src=\"files/images/function-completion.png\" width=\"30%\">\n</div>", "cell_type": "markdown", "metadata": {}}, {"source": "# Writing code", "cell_type": "markdown", "metadata": {}}, {"source": "Writing code in the notebook is pretty normal.", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 1, "outputs": [], "source": "def print_10_nums():\n for i in range(10):\n print i,", "metadata": {"collapsed": false, "trusted": false}}, {"cell_type": "code", "execution_count": 2, "outputs": [{"output_type": "stream", "name": "stdout", "text": "0 1 2 3 4 5 6 7 8 9\n"}], "source": "print_10_nums()", "metadata": {"collapsed": false, "trusted": false}}, {"source": "# Saving", "cell_type": "markdown", "metadata": {}}, {"source": "As of the latest stable version, the notebook autosaves. You should use the latest stable version. Really.", "cell_type": "markdown", "metadata": {}}, {"source": "# Magic functions", "cell_type": "markdown", "metadata": {}}, {"source": "IPython has all kinds of magic functions. Here's an example of comparing `sum()` with a list comprehension to a generator comprehension using the `%time` magic.", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 3, "outputs": [{"output_type": "stream", "name": "stdout", "text": "CPU times: user 24 ms, sys: 4 ms, total: 28 ms\nWall time: 27.4 ms\n"}, {"execution_count": 3, "output_type": "execute_result", "data": {"text/plain": "4999950000"}, "metadata": {}}], "source": "%time sum([x for x in range(100000)])", "metadata": {"collapsed": false, "trusted": false}}, {"cell_type": "code", "execution_count": 4, "outputs": [{"output_type": "stream", "name": "stdout", "text": "CPU times: user 8 ms, sys: 0 ns, total: 8 ms\nWall time: 8.11 ms\n"}, {"execution_count": 4, "output_type": "execute_result", "data": {"text/plain": "4999950000"}, "metadata": {}}], "source": "%time sum(x for x in range(100000))", "metadata": {"collapsed": false, "trusted": false}}, {"source": "The magics I use most are `%time` and `%prun` for profiling. You can run `%magic` to get a list of all of them, and `%quickref` for a reference sheet.", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 5, "outputs": [], "source": "%quickref", "metadata": {"collapsed": false, "trusted": false}}, {"source": "You can also do nutty things like run Perl code in the notebook with cell magics. This is especially cool for things like Cython code, where you can try out Cython really fast with the `%%cython` magic (you'll need to install it).", "cell_type": "markdown", "metadata": {}}, {"cell_type": "code", "execution_count": 6, "outputs": [{"output_type": "stream", "name": "stdout", "text": "whoa, perl!"}], "source": "%%perl\n\n$_ = \"whoa, python!\";\ns/python/perl/;\nprint", "metadata": {"collapsed": false, "trusted": false}}, {"source": "That's it for now!", "cell_type": "markdown", "metadata": {}}, {"source": "<style>\n @font-face {\n font-family: \"Computer Modern\";\n src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n }\n div.cell{\n width:800px;\n margin-left:16% !important;\n margin-right:auto;\n }\n h1 {\n font-family: Helvetica, serif;\n }\n h4{\n margin-top:12px;\n margin-bottom: 3px;\n }\n div.text_cell_render{\n font-family: Computer Modern, \"Helvetica Neue\", Arial, Helvetica, Geneva, sans-serif;\n line-height: 145%;\n font-size: 130%;\n width:800px;\n margin-left:auto;\n margin-right:auto;\n }\n .CodeMirror{\n font-family: \"Source Code Pro\", source-code-pro,Consolas, monospace;\n }\n .text_cell_render h5 {\n font-weight: 300;\n font-size: 22pt;\n color: #4057A1;\n font-style: italic;\n margin-bottom: .5em;\n margin-top: 0.5em;\n display: block;\n }\n \n .warning{\n color: rgb( 240, 20, 20 )\n } ", "cell_type": "markdown", "metadata": {}}], "nbformat_minor": 0}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# A quick tour of IPython Notebook"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This tour will work a little better in interactive mode, so it'll be better if you get IPython notebook installed and running. You can start it from a terminal by running\n",
"\n",
"`ipython notebook`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, we need to explain how to run cells. Try to run the cell below!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hi! This is a cell. Press the ▶ button above to run it\n"
]
}
],
"source": [
"import pandas as pd\n",
"\n",
"print(\"Hi! This is a cell. Press the ▶ button above to run it\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also run a cell with Ctrl+Enter or Shift+Enter. Experiment a bit with that."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"One of the most useful things about IPython notebook is its tab completion. \n",
"\n",
"Try this: click just after read_csv( in the cell below and press Shift+Tab (or Tab if you're using IPython 1.x) 4 times, slowly"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"pd.read_csv("
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After the first time, you should see this:\n",
"<div align=\"center\">\n",
"<img src=\"files/images/tab-once.png\" width=\"75%\">\n",
"</div>\n",
"\n",
"After the second time:\n",
"<div align=\"center\">\n",
"<img src=\"files/images/tab-twice.png\" width=\"75%\">\n",
"</div>\n",
"\n",
"After the fourth time, a big help box should pop up at the bottom of the screen, with the full documentation for the `read_csv` function:\n",
"<div align=\"center\">\n",
"<img src=\"files/images/tab-4-times.png\" width=\"90%\">\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I find this amazingly useful. I think of this as \"the more confused I am, the more times I should press Shift+Tab\". Nothing bad will happen if you tab complete 12 times.\n",
"\n",
"Okay, let's try tab completion for function names!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pd.r"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You should see this:\n",
"\n",
"<div align=\"center\">\n",
"<img src=\"files/images/function-completion.png\" width=\"30%\">\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Writing code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Writing code in the notebook is pretty normal."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print_10_nums()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def print_10_nums():\n",
" for i in range(10):\n",
" print(i),"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Saving"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As of the latest stable version, the notebook autosaves. You should use the latest stable version. Really."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Magic functions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"IPython has all kinds of magic functions. Here's an example of comparing `sum()` with a list comprehension to a generator comprehension using the `%time` magic."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%time sum([x for x in range(100000)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%time sum(x for x in range(100000))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The magics I use most are `%time` and `%prun` for profiling. You can run `%magic` to get a list of all of them, and `%quickref` for a reference sheet."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%quickref"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also do nutty things like run Perl code in the notebook with cell magics. This is especially cool for things like Cython code, where you can try out Cython really fast with the `%%cython` magic (you'll need to install it)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%perl\n",
"\n",
"$_ = \"whoa, python!\";\n",
"s/python/perl/;\n",
"print"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"That's it for now!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<style>\n",
" @font-face {\n",
" font-family: \"Computer Modern\";\n",
" src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n",
" }\n",
" div.cell{\n",
" width:800px;\n",
" margin-left:16% !important;\n",
" margin-right:auto;\n",
" }\n",
" h1 {\n",
" font-family: Helvetica, serif;\n",
" }\n",
" h4{\n",
" margin-top:12px;\n",
" margin-bottom: 3px;\n",
" }\n",
" div.text_cell_render{\n",
" font-family: Computer Modern, \"Helvetica Neue\", Arial, Helvetica, Geneva, sans-serif;\n",
" line-height: 145%;\n",
" font-size: 130%;\n",
" width:800px;\n",
" margin-left:auto;\n",
" margin-right:auto;\n",
" }\n",
" .CodeMirror{\n",
" font-family: \"Source Code Pro\", source-code-pro,Consolas, monospace;\n",
" }\n",
" .text_cell_render h5 {\n",
" font-weight: 300;\n",
" font-size: 22pt;\n",
" color: #4057A1;\n",
" font-style: italic;\n",
" margin-bottom: .5em;\n",
" margin-top: 0.5em;\n",
" display: block;\n",
" }\n",
" \n",
" .warning{\n",
" color: rgb( 240, 20, 20 )\n",
" } "
]
}
],
"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.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
475 changes: 474 additions & 1 deletion cookbook/Chapter 1 - Reading from a CSV.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading