Summary and Schedule
The Python Intro for Libraries lesson had a major redesign on June 17, 2024. This new Python lesson features a different dataset (of library usage data), uses JupyterLab instead of Spyder, and most of the content was rewritten. If you were familiar with the previous version of the lesson and are planning to teach it again, please give yourself time to review the lesson in full as your prepare.
This lesson is an introduction to programming in Python for library and information workers with little or no previous programming experience. It uses examples that are relevant to a range of library use cases, and is designed as a prerequisite for other Python lessons that will be developed in the future (e.g., web scraping, APIs). The lesson uses the JupyterLab computing environment and Python 3.
Prerequisites
Learners need to understand what files and directories are and what a working directory is.
Learners must install Python and JupyterLab, and download the dataset that will be used in the lesson, before the workshop begins.
Please see setup instructions below for details.
Learning Objectives
After attending this training, participants will be able to:
- Navigate the JupyterLab interface and run Python cells within a notebook.
- Assign values to variables, identify data types, and display values in a Jupyter Notebook.
- Create and manipulate lists in Python, including indexing, slicing, appending, and removing items to manage data collections effectively.
- Call built-in Python functions, and use the help function to understand their usage and troubleshoot errors.
- Use Python libraries like Pandas to import modules, load tabular data from CSV files, and perform basic data analysis.
- Apply ‘for’ loops to iterate over collections, using the accumulator pattern to aggregate values and trace variable states to predict loop outcomes.
- Manipulate pandas DataFrames to select data, calculate summary statistics, sort data, and save results in various formats, demonstrating basic data handling and analysis proficiency.
- Write Python programs using conditional logic with ‘if’, ‘elif’, and ‘else’ statements, including Boolean expressions and compound conditions within loops.
- Construct Python functions that encapsulate tasks, manage parameters, local, and global variables, and return values to enhance code modularity and readability.
- Transform complex datasets into a tidy format using pandas functions like ‘melt()’ for reshaping, ‘groupby()’ for aggregation, and ‘to_datetime()’ for date handling. Address practical challenges and demonstrate the benefits of tidy data for analysis.
- Create and customize data visualizations using Pandas and Plotly, generating various plot types (line, area, bar, histogram) to analyze trends and draw insights from time-series data.
- Prepare for advanced Python topics such as web scraping and APIs.
Setup Instructions | Download files required for the lesson | |
Duration: 00h 00m | 1. Getting Started |
How can I identify and use key features of JupyterLab to create and
manage a Python notebook? How do I run Python code in JupyterLab, and how can I see and interpret the results? |
Duration: 00h 20m | 2. Variables and Types |
How can I store data in Python? What are some types of data that I can work with in Python? |
Duration: 00h 45m | 3. Lists | How can I store multiple items in a Python variable? |
Duration: 01h 20m | 4. 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? |
Duration: 01h 45m | 5. Libraries & Pandas |
How can I extend the capabilities of Python? How can I use Python code that other people have written? How can I read tabular data? |
Duration: 02h 15m | 6. For Loops | How can I execute Python code iteratively across a collection of values? |
Duration: 02h 55m | 7. Looping Over Data Sets | How can I process many data sets with a single command? |
Duration: 03h 15m | 8. Using Pandas |
How can I work with subsets of data in a pandas DataFrame? How can I run summary statistics and sort columns of a DataFrame? How can I save DataFrames to other file formats? |
Duration: 03h 45m | 9. Conditionals | How can programs do different things for different data? |
Duration: 04h 10m | 10. Writing Functions |
How can I create my own functions? How do variables inside and outside of functions work? How can I make my functions easier to understand? |
Duration: 04h 35m | 11. Tidy Data with Pandas |
What are the benefits of transforming data into a tidy format for
analysis? How does the melt() function in pandas facilitate data tidying? What are some practical challenges when working with real-world datasets in Python, and how can they be addressed? :::::::::::::::::::::::::::::::::::::::::::::::::: |
Duration: 06h 15m | 12. Data Visualisation | How can I use Python tools like Pandas and Plotly to visualize library circulation data? |
Duration: 06h 45m | 13. Wrap-Up |
What have we learned? What else is out there and where do I find it? How can I make my programs more readable? |
Duration: 06h 55m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Installing Python Using Anaconda
Python is a popular language for research computing, and great for general-purpose programming as well. Installing all of its research packages individually can be a bit difficult, so we recommend Anaconda, an all-in-one installer.
Regardless of how you choose to install it, please make sure you install Python 3.6 or above. The latest 3.x version recommended on Python.org is fine.
We will teach Python using JupyterLab, a programming environment that runs in a web browser (JupyterLab will be installed by Anaconda). For this to work you will need a reasonably up-to-date browser. The current versions of the Chrome, Safari and Firefox browsers are all supported (some older browsers, including Internet Explorer version 9 and below, are not).
JupyterLab
We will teach Python using JupyterLab, a part of a family of Jupyter tools that includes Jupyter Notebook and JupyterLab, both of which provide interactive web environments where you can write and run Python code. If you installed Anaconda, JupyterLab is installed on your system. If you did not install Anaconda, you can install JupyterLab on its own using conda, pip, or other popular package managers.
Download the data
- Download this zip file and save it to your Desktop.
- Unzip the
data.zip
file, which should create a new folder calleddata
. - Create a new folder on your Desktop called
lc-python
and put thedata
folder in this folder.
This lesson uses circulation data in multiple CSV files from the Chicago Public Library system. The data was compiled from records shared by the Chicago Public Library in the data.gov catalog. Please do not download the circulation data from data.gov since the dataset you downloaded following the steps above has been altered for our purposes.