Skip to content
An introduction to Python and programming for wanna-be data scientists
Jupyter Notebook Python
Branch: master
Clone or download

Latest commit

Latest commit 9d53217 Apr 4, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
sample_package Add the sample_package folder to the project Sep 22, 2019
static Make links look nice with images Apr 2, 2020
.gitignore Add a simple .gitignore file Sep 15, 2019
00_intro_00_content.ipynb Make links look nice with images Apr 2, 2020
00_intro_01_review.ipynb Make links look nice with images Apr 2, 2020
00_intro_02_exercises.ipynb Make links look nice with images Apr 2, 2020
01_elements_00_content.ipynb Make links look nice with images Apr 2, 2020
01_elements_01_review.ipynb Make links look nice with images Apr 2, 2020
01_elements_02_exercises.ipynb Make links look nice with images Apr 2, 2020
02_functions_00_content.ipynb Make links look nice with images Apr 2, 2020
02_functions_01_review.ipynb Make links look nice with images Apr 2, 2020
02_functions_02_exercises.ipynb Make links look nice with images Apr 2, 2020
03_conditionals_00_content.ipynb Make links look nice with images Apr 2, 2020
03_conditionals_01_review.ipynb Make links look nice with images Apr 2, 2020
03_conditionals_02_exercises.ipynb Make links look nice with images Apr 2, 2020
04_iteration_00_content.ipynb Add new chapter 8 on map, filter, & reduce Apr 3, 2020
04_iteration_01_review.ipynb Make links look nice with images Apr 2, 2020
04_iteration_02_exercises.ipynb Make links look nice with images Apr 2, 2020
04_iteration_03_exercises.ipynb Make links look nice with images Apr 2, 2020
05_numbers_00_content.ipynb Add new chapter 8 on map, filter, & reduce Apr 3, 2020
05_numbers_01_review.ipynb Make links look nice with images Apr 2, 2020
05_numbers_02_exercises.ipynb Make links look nice with images Apr 2, 2020
06_text_00_content.ipynb Add new chapter 8 on map, filter, & reduce Apr 3, 2020
06_text_01_review.ipynb Make links look nice with images Apr 2, 2020
06_text_02_exercises.ipynb Make links look nice with images Apr 2, 2020
07_sequences_00_content.ipynb Add new chapter 8 on map, filter, & reduce Apr 3, 2020
07_sequences_01_review.ipynb Make links look nice with images Apr 2, 2020
07_sequences_02_exercises.ipynb Make links look nice with images Apr 2, 2020
08_mfr_00_content.ipynb Add new chapter 8 on map, filter, & reduce Apr 3, 2020
08_mfr_01_review.ipynb Add new chapter 8 on map, filter, & reduce Apr 3, 2020
08_mfr_02_exercises.ipynb Add new chapter 8 on map, filter, & reduce Apr 3, 2020
LICENSE Initial commit Sep 15, 2019
README.md Make links look nice with images Apr 2, 2020
full_house.bin Refurbish chapter 06 Mar 16, 2020
lorem_ipsum.txt Streamline previous content Oct 30, 2019
poetry.lock Update dependencies Feb 2, 2020
pyproject.toml Bump version number Mar 30, 2020
requirements.txt Update dependencies Feb 2, 2020
sample_module.py Add video and streamline content Mar 30, 2020
stream.py Add exercise on packing/unpacking with functions Nov 20, 2019
umlauts.txt Refurbish chapter 06 Mar 16, 2020

README.md

An Introduction to Python and Programming

The purpose of this repository is to serve as an interactive book for a thorough introductory course on programming in the Python language.

The course's main goal is to prepare the student for further studies in the "field" of data science.

The chapters are laid out in Jupyter notebooks which are a de-facto standard for exchanging code and analyses among data science professionals and researchers. They can be viewed in a web browser either statically on nbviewer or interactively (i.e., you can execute the code) on mybinder :

However, it is recommended to install Python and Jupyter locally and run the code in the notebooks on one's own machine in the JupyterLab application. Precise installation instructions are either in Chapter 0 or further below.

Feedback

Feedback is highly encouraged and will be incorporated. Simply open an issue in the issues tracker or initiate a pull request if you are familiar with the concept. Simple issues that anyone can help fix are, for example, spelling mistakes or broken links. If you feel that some topic is missing entirely, you may also mention that. The materials here are considered a permanent work-in-progress.

A "Show HN" post about this course was made on Hacker News and some ideas for improvement were discussed there.

Videos

Presentations on the chapters are available either via the individual links to YouTube above or this playlist .

Prerequisites

To be suitable for total beginners, there are no formal prerequisites. It is only expected that the student has:

  • a solid understanding of the English language,
  • knowledge of basic mathematics from high school,
  • the ability to think conceptually and reason logically, and
  • the willingness to invest around 90 - 120 hours on this course.

Installation

To follow this course, a working installation of Python 3.7 or higher is expected.

A popular and beginner friendly way is to install the Anaconda Distribution that not only ships Python but comes pre-packaged with a lot of third-party libraries from the so-called "scientific stack". Just go to the download section and install the latest version (i.e., 2019-10 with Python 3.7 at the time of this writing) for your operating system.

Then, among others, you will find an entry "Anaconda Navigator" in your start menu like below. Click on it.

A window opens showing you several applications that come with the Anaconda Distribution. Now, click on "JupyterLab."

A new tab in your web browser opens with the website being "localhost" and some number (e.g., 8888). This is the JupyterLab application that is used to display and run the notebooks mentioned above. On the left, you see the files and folders in your local user folder. This file browser works like any other. In the center, you have several options to launch (i.e., "create") new files.

Next, to download the course's materials as a ZIP file, click on the green "Clone or download" button on the top right on this website. Then, unpack the ZIP file into a folder of your choosing, ideally somewhere within your personal user folder so that the files show up right away in JupyterLab.

Alternative Installation (for Instructors)

Python can also be installed in a "pure" way as obtained from its core development team (i.e., without any third-party packages installed). However, this may be too "advanced" for a beginner as it involves working with a terminal emulator , which looks like the one in the picture below and is used without a mouse by typing commands into it.

Assuming that you already have a working version of Python 3.7 or higher installed (cf., the official download page ), the following summarizes the commands to be typed into a terminal emulator to get the course materials up and running on a local machine without the Anaconda Distribution. You are then responsible for understanding the concepts behind them.

First, the git command line tool is a more professional way of "cloning" the course materials as compared to downloading them in a ZIP file.

  • git clone https://github.com/webartifex/intro-to-python.git

This creates a new folder intro-to-python with all the materials of this repository in it.

Inside this folder, it is recommended to create a so-called virtual environment with Python's venv module. This must only be done the first time. A virtual environment is a way of isolating the third-party packages installed by different projects, which is considered a best practice.

  • python -m venv venv

The second venv is the environment's name and by convention often chosen to be venv. However, it could be another name as well.

From then on, each time you want to resume work, go back into the intro-to-python folder inside your terminal and "activate" the virtual environment (venv is the name chosen before).

  • source venv/bin/activate

This may change how the terminal's command prompt looks.

poetry and virtualenvwrapper are popular tools to automate the described management of virtual environments.

After activation for the first time, you must install the project's dependencies (= the third-party packages needed to run the code), most notably JupyterLab in this project (the "python -m" is often left out but should not be; if you have poetry installed, you may just type poetry install instead).

  • python -m pip install -r requirements.txt

With everything installed, you can now do the equivalent of clicking the "JupyterLab" entry in the Anaconda Navigator.

  • jupyter lab

This opens a new tab in your web browser just as above.

Interactive Presentation Mode & Live Coding

The requirements.txt file also installs the nbextensions for Jupyter notebooks, the black code formatting tool (incl. the blackcellmagic Jupyter extension) and the RISE Jupyter extension. With them, the instructor can easily re-format code in a class session and execute code in presentation mode.

Note: Currently, the RISE extension only works with the older notebook command.

  • jupyter notebook (so, jupyter lab may not be used).

After installing the dependencies, the instructor must copy the extensions' JavaScript and CSS files into Jupyter's search directory.

  • jupyter contrib nbextension install --user

Now, the instructor can enable/disable the various Jupyter notebook extensions.

Note: The extension "Collapsible Headings" may interfere with the RISE presentation if hotkeys are enabled.

About the Author

Alexander Hess is a PhD student at the Chair of Logistics Management at the WHU - Otto Beisheim School of Management where he conducts research on urban delivery platforms and teaches an introductory course on Python (cf., Fall Term 2019, Spring Term 2020).

Connect him on LinkedIn.

You can’t perform that action at this time.