In this module, we’ll focus on different ways to get data into Python.

We’ll explore different APIs, and use examples from BART, the US Census, and the City of Los Angeles.

In this module as in all the others, the course videos will provide the basic concepts and backgrounds. As you watch them, follow along in the notebook (which is in your GitHub repository). Explore the objects, try different things, and experiment. Don’t worry if you don’t get every last detail – we’ll use the class time to practice and introduce more examples. 

Learning objectives

By the end of this module, you should be able to:

  1. Formulate API calls and use the requests library to access data
  2. Clean and parse the returned data
  3. Access census data via the Census API and cenpy
  4. Use functions to simplify your code
  5. Design simple plots and maps using pandas and geopandas

Required Readings

Blumgart, Jake. 2020. Up to code. Planning, April 2020.

Andrews, Clint et al. 2022. AI in Planning. Opportunities and Challenges and How to Prepare. American Planning Association White Paper.

Both of these readings provide some examples of data science applications for urban planning. As you read them, think about:

  • What examples of data science for planning excite / resonate with you most
  • What problems with urban data science you think are the most challenging (either those in the readings, or others from your experience)

Optional Readings

Kang, Wei et al. 2019. Defining urban data science. Environment and Planning B: Urban Analytics and City Science, 6(9): 1756–1768.

Video 1a: The BART API

We’ll explore how to use an Application Programming Interface (API), using the example of train departure times from BART.

As you watch the video, follow along with the code here.

Video 1b: Using functions

We’ll package API calls into a function, creating more concise, readable, and modular code.

As you watch the video, follow along with the code here.

Video 1c: Getting census data

This lecture demonstrates the use of the US Census Bureau API to access a rich variety of demographic and housing data.

As you watch the video, follow along with the code here.

Video 1d: Using cenpy

We’ll explore the cenpy library, which is a simpler way to obtain census data in many circumstances, and introduce the mapping capabilities of the geopandas library.

As you watch the video, follow along with the code here.

Video 1e: The Socrata API

We’ll examine the Socrata API, which provides access to many government datasets. 

As you watch the video, follow along with the code here.

Please take the quiz below to check your understanding of this module.

Quiz for currently enrolled UCLA students

Quiz for other learners

Class practice

This notebook practices the concepts that we’ve developed in the lecture notebooks. We’ll work through it in class.

It’s the Module 1 class activity in your GitHub repository here. 

You have now completed Module 1. Please navigate to the homepage or to the next module by using the green navigation bar at the top.