Class 1 in-class exercise

Class 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
2024-09-20 22:01:44 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_yello_taxi_trips.csv
2021_yellow_taxi_trips.csv
LICENSE.md
Python Coding for Public Policy, Spring 2024 discussion threads.json
_build
_config.yml
_static
_toc.yml
assignments.md
conf.py
curve.ipynb
data
extras
final_project
final_project.md
home.md
hw_0.ipynb
hw_1.ipynb
hw_2.ipynb
hw_3.ipynb
hw_4.ipynb
index.md
joining_late.md
lecture_0.ipynb
lecture_1.ipynb
lecture_1_exercise.ipynb
lecture_1_exercise_solution.ipynb
lecture_2.ipynb
lecture_2_exercise.ipynb
lecture_3.ipynb
lecture_3.slides.html
lecture_3_exercise.ipynb
lecture_3_exercise_solution.ipynb
lecture_4.ipynb
lecture_5.ipynb
lecture_5_exercise_solution.ipynb
lecture_6.ipynb
meta
meta.md
nbdime_config.json
pyproject.toml
resources.md
rise.css
shorten.md
solutions
syllabus.md
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.

# your code here