Plotting and Programming in Python

This lesson is an introduction to programming in Python for people with little or no previous programming experience. It uses plotting as its motivating example, and is designed to be used in both Data Carpentry and Software Carpentry workshops. The first half of this lesson references the Jupyter Notebook, but can be taught using a regular Python interpreter as well. The second half of the lessons are intended to be writen using a text editor. Please note that this lesson uses Python 3 rather than Python 2.

Prerequisites

  1. Learners need to understand what files and directories are, what a working directory is, and how to start a Python interpreter.

  2. Learners must install Python before the workshop starts.

  3. Learners must get the gapminder data before class starts: please download and unzip the file python-novice-gapminder-data.zip.

    Please see the setup instructions for details.

Schedule

Setup Download files required for the lesson
00:00 1. Running and Quitting How can I run Python programs?
00:10 2. Variables and Assignment How can I store data in programs?
00:20 3. Numeric Data Types What kinds of data do programs store?
How can I convert one type to another?
00:25 4. Sequence Types: Strings, Tuples and Lists What is a sequence in Python?
What is the difference between strings, tuples, and lists?
How can we access items in a sequence?
00:40 5. Sets and Dictionaries What is a set?
What is a dictionary?
00:55 6. More on Iterable Data Types What do sequences, sets, and dictionaries have in common?
How do they differ?
When should I use each type?
01:05 7. For Loops How can I make a program do many things?
01:20 8. Break Break
01:35 9. Comparisons and Conditionals How can programs do different things for different data?
01:55 10. Built-in Functions and Help How can I use built-in functions?
How can I find out what they do?
What kind of errors can occur in programs?
02:05 11. Libraries How can I use software that other people have written?
How can I find out what that software does?
02:15 12. Reading Tabular Data into Pandas DataFrames How can I read tabular data?
02:25 13. More with Pandas DataFrames How can I do statistical analysis of tabular data?
02:30 14. Plotting How can I plot my data?
02:45 15. Writing Functions How can I create my own functions?
03:00 16. Review Exercise How can we put together all of yesterday’s material?
03:20 17. Command-Line Programs How can I write Python programs that will work like Unix command-line tools?
03:50 18. Trying Different Methods How do I plot multiple data sets using different methods?
04:20 19. Break Break
04:35 20. Program Flags How can I make an easy shortcut to analyze all files at once using a program flag?
04:45 21. Defensive Programming How do I predict and avoid user confusion?
05:00 22. Refactoring When should I reorganize my code so it is more clear and readable for others?
How can I organize my code so that it is useable in other places?
Why do I almost always want to write my code as though it will be used somewhere else?
05:20 23. Running Scripts and Importing How can I import some of my work even if it is part of a program?
05:40 24. Programming Style How can I make my programs more readable?
How do most programmers format their code?
How can programs check their own operation?
05:50 25. Wrap-Up What have we learned?
What else is out there and where do I find it?
06:00 Finish

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.