"In this course we will be exploring some of the most popular Python packages:\n",
"In this course we will be exploring some of the most popular Python packages:\n",
"* NumPy - efficient and fast numerical computing package\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",
"* 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",
"* pandas - provides high-level data structures and functions for work with tabular data\n",
"\n",
"\n",
"\n",
"\n",
"## 1.1. Why Python\n",
"## 1.1. Why Python\n",
...
@@ -26,8 +25,13 @@
...
@@ -26,8 +25,13 @@
"\n",
"\n",
"\n",
"\n",
"## 1.2. Course structure\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",
"This is a taught course but the notebooks can also be studied independently. During teaching, you are expected to follow the instructor whilist running all code blocks by yourself. The course is divided into 4 core notebooks:\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",
"- Notebook 1: Warm-up\n",
"- Notebook 2: Numpy\n",
"- Notebook 3: Matplotlib\n",
"- Notebook 4: Pandas\n",
"\n",
"There are also additional notebooks starting `python-data-extra`, which introduce new functionality or explore specialised packages for specific data science applications. If time allows we will explore some of these at the end of the day.\n",
"\n",
"\n",
"## 1.3. Ask\n",
"## 1.3. Ask\n",
"*The art and science of asking questions is the source of all knowledge.*\n",
"*The art and science of asking questions is the source of all knowledge.*\n",
...
@@ -175,7 +179,7 @@
...
@@ -175,7 +179,7 @@
"metadata": {},
"metadata": {},
"source": [
"source": [
"## 3.2 Introspection\n",
"## 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."
"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?`. You can also find out about a function by moving your cursor to within a function's parentheses and pressing `Shift + TAB` to bring up documentation. Let's try this out."
]
]
},
},
{
{
...
@@ -184,7 +188,7 @@
...
@@ -184,7 +188,7 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"firstString?"
"firstString? # Use Question mark introspection"
]
]
},
},
{
{
...
@@ -193,7 +197,7 @@
...
@@ -193,7 +197,7 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"print?"
"print() # Use Shift + TAB"
]
]
},
},
{
{
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# 1. Introduction
# 1. Introduction
Thank you for taking this course. Its purpose is to show you how you can use Python for data science techniques such as
Thank you for taking this course. Its purpose is to show you how you can use Python for data science techniques such as
* statistical modeling
* statistical modeling
* data analysis
* data analysis
* data visualisation
* data visualisation
* machine learning
* machine learning
The course aims to build on your existing skills in Python and is **not** meant for beginners.
The course aims to build on your existing skills in Python and is **not** meant for beginners.
In this course we will be exploring some of the most popular Python packages:
In this course we will be exploring some of the most popular Python packages:
* NumPy - efficient and fast numerical computing package
* NumPy - efficient and fast numerical computing package
* pandas - provides high-level data structures and functions for work with tabular data
* matplotlib - most popular library for producing plots and other two-dimensional data visualizations
* matplotlib - most popular library for producing plots and other two-dimensional data visualizations
*SciPy - a collection of packages addressing a number of different standard problem domains in scientific computing.
*pandas - provides high-level data structures and functions for work with tabular data
## 1.1. Why Python
## 1.1. Why Python
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.
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.
## 1.2. Course structure
## 1.2. Course structure
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.
This is a taught course but the notebooks can also be studied independently. During teaching, you are expected to follow the instructor whilist running all code blocks by yourself. The course is divided into 4 core notebooks:
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.
- Notebook 1: Warm-up
- Notebook 2: Numpy
- Notebook 3: Matplotlib
- Notebook 4: Pandas
There are also additional notebooks starting `python-data-extra`, which introduce new functionality or explore specialised packages for specific data science applications. If time allows we will explore some of these at the end of the day.
## 1.3. Ask
## 1.3. Ask
*The art and science of asking questions is the source of all knowledge.*
*The art and science of asking questions is the source of all knowledge.*
-- Thomas Berger
-- Thomas Berger
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!
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!
## 1.4. Failure
## 1.4. Failure
Coding is all about failure and learning.
Coding is all about failure and learning.
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.
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.
## 1.5. After the course
## 1.5. After the course
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.
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.
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.
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 id: tags:
%% Cell type:markdown id: tags:
# 2. Environment
# 2. Environment
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.
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.
To try it out let's write our first line of Python code!
To try it out let's write our first line of Python code!
Simply select the code snippet below and click the `Run` button in the toolbar near the top of the window.
Simply select the code snippet below and click the `Run` button in the toolbar near the top of the window.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
print("Hello world")
print("Hello world")
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
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.
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.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
importthis
importthis
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
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.
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.
Actually this text block is also interactive and you can change it. Try it out by double clicking on it!
Actually this text block is also interactive and you can change it. Try it out by double clicking on it!
## Heading
## Heading
### Subheading
### Subheading
#### sub-subheading
#### sub-subheading
`code snippet`
`code snippet`
[This is a link](https://www.ed.ac.uk/information-services/help-consultancy/is-skills)
[This is a link](https://www.ed.ac.uk/information-services/help-consultancy/is-skills)
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)
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 id: tags:
%% Cell type:markdown id: tags:
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.
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.
These notebooks will stay bound to your Noteable account and you can work on them outside of the course as well.
These notebooks will stay bound to your Noteable account and you can work on them outside of the course as well.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Useful operations
### Useful operations
-**Clearing all output** - `Kernel/Restart & Clear output`
-**Clearing all output** - `Kernel/Restart & Clear output`
-**Deleting a block** - `Edit/Delete Cell`
-**Deleting a block** - `Edit/Delete Cell`
-**Saving a notebook localy** - `File/Download As/Notebook(.ipynb)`
-**Saving a notebook localy** - `File/Download As/Notebook(.ipynb)`
-**Closing** - not recommended to close a notebook by closing the window. You should close it from the toolbar `File/Close and Halt`.
-**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 id: tags:
%% Cell type:markdown id: tags:
# 3. Tips
# 3. Tips
Jupyther notebooks go to great lenghts to make Python look less intimidating and they provide extra tools to get you up and coding faster.
Jupyther notebooks go to great lenghts to make Python look less intimidating and they provide extra tools to get you up and coding faster.
## 3.1 Tab completion
## 3.1 Tab completion
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.
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 id: tags:
%% Cell type:code id: tags:
``` python
``` python
firstString="Hello world"
firstString="Hello world"
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
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.
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.
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.
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?`. You can also find out about a function by moving your cursor to within a function's parentheses and pressing `Shift + TAB` to bring up documentation. Let's try this out.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
firstString?
firstString? # Use Question mark introspection
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
print?
print() # Use Shift + TAB
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## 3.3 Importing packages
## 3.3 Importing packages
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:
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 id: tags:
%% Cell type:code id: tags:
``` python
``` python
import numpy as np
import numpy as np
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
The `as` statement and the name after it is not necessarry but strongly encouraged.
The `as` statement and the name after it is not necessarry but strongly encouraged.