Newer
Older
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Introduction\n",
"\n",
"Thank you for taking this course. Its purpose is to show you how you can use Python for data science techniques such as \n",
"* statistical modeling\n",
"* data analysis\n",
"* data visualisation\n",
"* machine learning\n",
"\n",
"The course aims to build on your existing skills in Python and is **not** meant for beginners. \n",
"\n",
"In this course we will be exploring some of the most popular Python packages:\n",
"* NumPy - efficient and fast numerical computing package\n",
"* pandas - provides high-level data structures and functions for work with tabular data\n",
"* matplotlib - most popular library for producing plots and other two-dimensional data visualizations\n",
"* SciPy - a collection of packages addressing a number of different standard problem domains in scientific computing.\n",
"For many people, the Python programming lanugage has strong appeal. Since it first appeared in 1991, Python has become one of the most important programming languages today. Among interpreted languages, for various historical and cultural reasons, Python has developed a large and active scientific computing and data analysis community. In the last 10 years, Python has gone from bleeding-edge and experimental to one of the most important languages for data science machine learning and general software development in academia and industry.\n",
"\n",
"\n",
"## 1.2. Course structure\n",
"This is a taught course but the notebooks can also be studied independently. During teaching particular examples will be given directly out of the notebooks. You are expected to follow the instructor whilist running all code blocks by yourself.\n",
"The course is divided into 1h 30m sessions with a coffee break in between. Each of the two sessions will be split into teaching and exercises at the end.\n",
"\n",
"## 1.3. Ask\n",
"*The art and science of asking questions is the source of all knowledge.*\n",
"\n",
"-- Thomas Berger\n",
"\n",
"This course should be more of a conversation, therefore do not hesitate to stop the instructors and ask for questions at any time. The demonstrators are there to help you during exercises as well. Furthermore you can also ask other people within the course for help and advice!\n",
"\n",
"## 1.4. Failure\n",
"\n",
"Coding is all about failure and learning.\n",
"\n",
"Often you would have to fail several times before making something work but after that you can redo it immediately. That being said, do not be afraid to experiment and fail! Often a useful error message will be printed which will help you solve the issue.\n",
"\n",
"## 1.5. After the course\n",
"These notebooks will stay bound to your account after the course which means that you will be able to finish the exercises in your own free time or even redo a whole notebook if you were uncertain about a particular topic.\n",
"\n",
"\n",
"All of the code we are writing here can be downloaded as generic python scripts which you can run on any other machine independent of Noteable/Jupyther."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Environment\n",
"For the duration of this session we will be using Jupyter Notebooks. They are simply a web-based interface for Python which can also have instructions inbetween code blocks.\n",
"\n",
"To try it out let's write our first line of Python code!\n",
"Simply select the code snippet below and click the `Run` button in the toolbar near the top of the window."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Hello world\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To save yourself a couple of clicks you can also press `Shift + Return` after highlighting a code cell and it will execute. Try it out."
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import this"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All cells in Jupyter are interactive and you can change them whenever you want. For example you can go back to the print statement above and change it to print whatever you want.\n",
"Actually this text block is also interactive and you can change it. Try it out by double clicking on it!\n",
"\n",
"## Heading\n",
"### Subheading\n",
"#### sub-subheading\n",
"`code snippet`\n",
"\n",
"[This is a link](https://www.ed.ac.uk/information-services/help-consultancy/is-skills)\n",
"\n",
"We would encourage you to write your own notes throughout the course by adding new blocks. If you want to learn more - [Markdown Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can add a new cell by clicking the `+` on the toolbar. From the dropdown menu next to it, you can choose the type of block. The most useful ones are `Python` and `Markdown`. This cell is written in Markdown, it is essentailly a simplified markup lanugage. Once you are finished editing a text cell, press `Shift + Return` to return it to a readable state.\n",
"\n",
"These notebooks will stay bound to your Noteable account and you can work on them outside of the course as well."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Useful operations\n",
"- **Clearing all output** - `Kernel/Restart & Clear output`\n",
"- **Deleting a block** - `Edit/Delete Cell`\n",
"- **Saving a notebook localy** - `File/Download As/Notebook(.ipynb)`\n",
"- **Closing** - not recommended to close a notebook by closing the window. You should close it from the toolbar `File/Close and Halt`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3. Tips\n",
"\n",
"Jupyther notebooks go to great lenghts to make Python look less intimidating and they provide extra tools to get you up and coding faster.\n",
"## 3.1 Tab completion\n",
"One of the major benefits of Jupyter - when you start writing something you can press `Tab` before finishing it and the environemnt will type in the rest of it or propose various completions in a drop-down menu."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"firstString = \"Hello world\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the block above, start typing `firstString` in the block below and press `Tab` at some point before you finish writing it. It should complete it automatically."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This can also be applied to methods of objects (will be explored later). Using the variable decalared above, in the code block below you can type in `firstString.`, press `Tab` and Jupyter will present you with various methods applicable to a string."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3.2 Introspection\n",
"Jupyter can provide you with information about every object in its namespace. (Don't worry if you don't know what an object is exactly, everything in Python is an object). This can be done by typing in the name of any object followed by a question mark. Eg. `print?`. Let's try this on the previous declared variable."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"firstString?"
]
},
{
"cell_type": "code",
"metadata": {},
"outputs": [],
"source": [
"print?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3.3 Importing packages\n",
"To bring in the extra functionality of Pythons packages we need to use `import` statements. Whenever you import a package once it remains loaded in the background until you reset the Jupyter kernel. To import NumPy we have to type in:"
]
},
{
"cell_type": "code",
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `as` statement and the name after it is not necessarry but strongly encouraged."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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",