Lecture 1 in-class exercise

Lecture 1 in-class exercise#

We’ll be doing calculations on 2021 Yellow Taxi Trips data. We’ll live-code this together.

Step 0#

The data needs to available on the machine where Python is running in order to process it, so let’s download from the NYC Open Data site directly:

!wget -O 2021_yellow_taxi_trips.csv --no-verbose https://data.cityofnewyork.us/resource/m6nq-qud6.csv
2025-03-17 00:00:28 URL:https://data.cityofnewyork.us/resource/m6nq-qud6.csv [136065] -> "2021_yellow_taxi_trips.csv" [1]

This is using a command-line program to do the downloading. We’ll download data ourselves manually later. Look at the files in the current directory:

!ls
2021_yellow_taxi_trips.csv          lecture_1_exercise.ipynb
LICENSE.md                          lecture_1_exercise_solution.ipynb
Makefile                            lecture_2.ipynb
__pycache__                         lecture_2.slides.html
_build                              lecture_2_exercise.ipynb
_config.yml                         lecture_2_exercise_2_solution.ipynb
_static                             lecture_3.ipynb
_toc.yml                            lecture_3.slides.html
assignments                         lecture_3_exercise_solution.ipynb
assignments.md                      lecture_4.ipynb
attendance.csv                      lecture_4.slides.html
conf.py                             lecture_5.ipynb
curve.ipynb                         lecture_5.slides.html
data                                lecture_5_exercise_solution.ipynb
extras                              lecture_6.ipynb
final_project                       lecture_6.slides.html
final_project.md                    lectures.md
home.md                             meta
hw_0.ipynb                          meta.md
hw_1.md                             nbdime_config.json
hw_2.ipynb                          pyproject.toml
hw_3.ipynb                          registration.md
hw_4.ipynb                          resources.md
index.md                            results
joining_late.md                     simple.html
lecture_0.ipynb                     simple.ipynb
lecture_0.slides.html               solutions
lecture_1.ipynb                     syllabus.md
lecture_1.slides.html               tmp

You should see 2021_yellow_taxi_trips.csv there.

Step 1#

Print out the trip distances.

# your code here

Step 2#

Calculate the average ride distance.

# your code here

Step 3#

Your turn! Calculate the percent of trips that were paid for by credit card.

  • The data dictionary will be helpful - see the Attachment on the dataset page.

  • You’re welcome to talk with your neighbors.

# your code here