class: center, titleslide
# Python Course # Part 1: Introduction + Python
--- layout: true class: mainlayout --- class: tocslide exclude: true .left-column[ ## About me ] .right-column[
] --- class: tocslide .left-column[ ## Program ] .right-column[ ### What will we be doing?
**Five days:**
1) Introduction to Python (+ Python worfklow)
2) Handling data with `Pandas`
3) Gathering data from the web
4) Natural Language Processing
5) Miscellaneous topics
] --- class: tocslide .left-column[ ## Program ## Basic
Principles ] .right-column[
### Basic Principles of this course:
1) I cannot inject you with Python skills 2) **It is up to you to make yourself proficient with Python** ] -- .right-column-next[
### My goal:
Make it more efficient for you to **teach Python to yourself**
] -- .right-column-next[
### How? 1. By providing starting points 2. By pointing out common pitfalls ] --- class: tocslide .left-column[ ## Program ## Basic
Principles ## Structure ] .right-column[
### Structure: **Each day consists of three elements:**
1) Lecture (recording)
Introduce basic constructs and terminology 2) Demonstration (recording)
Demonstrate how I interact with the tools and write code 3) Hands-on problems
Get hands-on experience by solving problems ] --- class: tocslide .left-column[ ## Program ## Basic
Principles ## Structure ## Materials ] .right-column[
### Slides: All of the slides are made available here:
GitHub page
### Python materials:
All materials are available here: 1)
Learn Python for Research (GitHub)
2)
Natural Language Processing (NLP) Tutorial (GitHub)
] --- class: tocslide .left-column[ ## Program ## Basic
Principles ## Structure ## Materials ## Assignment ] .right-column[
### Assignment The problems (will be introduced in more detailed later) also serve as the "assignment" for this Limperg course. You will need to complete and hand-in the four problem notebooks by: **June 29th 2020**
**Two remarks:** 1) Any problems under `Part 3: ...` are not required for the assignment 2) You will be able to complete most problems during the course ] --- class: tocslide .left-column[ ## Program ## Basic
Principles ## Structure ## Materials ## Assignment ## This lecture ] .right-column[ ### Agenda
1. Why Python? 2. Python eco-system 3. Using Python 4. Jupyter Notebook 5. Python syntax ] --- class: tocslide .left-column[ ## Why
Python? ] .right-column[
(Source: https://stackoverflow.blog/2017/09/06/incredible-growth-python/)
] --- class: tocslide .left-column[ ## Why
Python? ] .right-column[
(Source: https://insights.stackoverflow.com/survey/2019#overview)
] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ] .right-column[
### Python 2 vs. Python 3:
Simple: always use Python 3 unless you have to use Python 2. Python 3 receives new updates, Python 2.7 will be phased out in 2020.
**Note!** Python 3 syntax is not always backwards compatible!
`print 'Hello, world!'`
Only works in Python 2.7 `print('Hello, world!')`
Works in Python 2.7 and Python 3.X
### We will use Python 3.7 (or Python 3.6+) ] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ] .right-column[
### Modules and packages A module/package is Python code that you "import" to add functionality. **Two types of modules/packages:** 1. Built-in modules that are included with Python 2. Third-party modules/packages
The Python Package Index hosts more than 240,000 packages! **Example:** `import os`
Standard module `import pandas as pd`
Third-party module ] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ] .right-column[
### Modules and packages **How to install third-party modules/packages?** Use `pip` to install packages hosted on the Python Package Index Use `conda` to install packages hosted by `Anaconda` or `Conda-Forge`
] -- .right-column-next[ ### Recommendation:
always start with the default Anaconda 3 distribution! **Anaconda:** Python bundled with most used data science packages.
**For more info:**
Anconda Distribution website
] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ] .right-column[ ### How to run Python code?
1) Save code to `.py` file and run from command line: `python file.py`
2) Use an interactive console in the command line: `python` or `ipython`
**3) Use Jupyter Labs + Notebooks!** ] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ## Jupyter
Labs ] .right-column[ ### Jupyter Labs
Try it in your browser
] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ## Jupyter
Labs ## Jupyter
Notebook ] .right-column[ ### Jupyter Notebook
Try it in your browser
] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ## Jupyter
Notebook ] .right-column[ ### Jupyter Notebook
] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ## Jupyter
Notebook ] .right-column[ ### Jupyter Lab / Notebook #### How does it work:
**How to start:** 1. Open up a command line / terminal 2. Change to project directory using `cd` 3. Type: `jupyter lab` or `jupyter notebook` **How to stop:**
Press `ctrl+c` in command line / terminal ] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ## Jupyter
Notebook ] .right-column[ ### Jupyter Notebook Using a Jupyter Notebook is largely self-explanatory.
**Most relevant shortcuts for reference purposes:**
] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ## Jupyter
Notebook ## Python
syntax ] .right-column[ ### Python syntax is (relatively) easy!
] -- .right-column-next[ ### Where to start?
I recommend to use my
Python Basics Notebook
] --- class: tocslide .left-column[ ## Why
Python? ## Python
Eco-system ## Using
Python ## Jupyter
Notebook ## Python
syntax ] .right-column[ ### A couple of caveats 1) It is best practice to include all imports at the start 2) The spacing (i.e. tabs) are not just for looks!
3) Avoid "blind" `try` and `except` blocks.
] --- class: tocslide .left-column[ ## Get
Started! ] .right-column[
What is next?
## Setup: 1. Make sure you have Anaconda installed 2. Make sure you downloaded the materials from GitHub 2. Make sure you can start / open a Jupyter Lab ## Demonstration: Watch the demonstration video, see Discord for the link. ## Problems: Solve tasks in the "basic_python_problems.ipynb" notebook. ] --- class: tocslide exclude: true .left-column[ ## Closing
remarks ] .right-column[
Questions?
] --- class: tocslide exclude: true .left-column[ ## Closing
remarks ## Demonstration ] .right-column[
Demonstration
] --- class: tocslide exclude: true .left-column[ ## Closing
remarks ## Demonstration ## Mini-task ] .right-column[ ## Setup: 1. Make sure you have Anaconda installed 2. Make sure you downloaded the materials from GitHub 2. Make sure you can start / open a Jupyter Notebook ## Mini-tasks: **Goal:** Solve tasks in the "basic_python_tasks.ipynb" notebook. 1. Open a Jupyter Notebook in the `limperg_python_2019` folder 2. Solve the basic Python tasks
Find them in `minitasks > day_1 > basic_python_tasks.ipynb` You will need these notebooks: -
Python tutorial
-
Python Basics Notebook
]