#!/usr/bin/env python # coding: utf-8 # # Workbook # # Use this notebook to complete the exercises throughout the workshop. # # #### Table of Contents # - [Section 1 – Getting Started with Pandas](#Section-1) # - [Section 2 – Data Wrangling](#Section-2) # - [Section 3 – Data Visualization](#Section-3) # # --- # # ### Section 1 # # #### Exercise 1.1 # ##### Create a DataFrame by reading in the `2019_Yellow_Taxi_Trip_Data.csv` file. Examine the first 5 rows. # In[ ]: # #### Exercise 1.2 # ##### Find the dimensions (number of rows and number of columns) in the data. # In[ ]: # #### Exercise 1.3 # ##### Using the data in the `2019_Yellow_Taxi_Trip_Data.csv` file, calculate summary statistics for the `fare_amount`, `tip_amount`, `tolls_amount`, and `total_amount` columns. # In[ ]: # #### Exercise 1.4 # ##### Isolate the `fare_amount`, `tip_amount`, `tolls_amount`, and `total_amount` for the longest trip by distance (`trip_distance`). # In[ ]: # --- # # ### Section 2 # # #### Exercise 2.1 # ##### Read in the meteorite data from the `Meteorite_Landings.csv` file, rename the `mass (g)` column to `mass`, and drop all the latitude and longitude columns. Sort the result by mass in descending order. # In[ ]: # #### Exercise 2.2 # ##### Using the meteorite data from the `Meteorite_Landings.csv` file, update the `year` column to only contain the year, convert it to a numeric data type, and create a new column indicating whether the meteorite was observed falling before 1970. Set the index to the `id` column and extract all the rows with IDs between 10,036 and 10,040 (inclusive) with `loc[]`. # # ###### **Hint 1**: Use `year.str.slice()` to grab a substring. # # ###### **Hint 2**: Make sure to sort the index before using `loc[]` to select the range. # # ###### **Bonus**: There's a data entry error in the `year` column. Can you find it? (Don't spend too much time on this.) # In[ ]: # #### Exercise 2.3 # ##### Using the meteorite data from the `Meteorite_Landings.csv` file, create a pivot table that shows both the number of meteorites and the 95th percentile of meteorite mass for those that were found versus observed falling per year from 2005 through 2009 (inclusive). Hint: Be sure to convert the `year` column to a number as we did in the previous exercise. # In[ ]: # #### Exercise 2.4 # ##### Using the meteorite data from the `Meteorite_Landings.csv` file, compare summary statistics of the mass column for the meteorites that were found versus observed falling. # In[ ]: # #### Exercise 2.5 # ##### Using the taxi trip data in the `2019_Yellow_Taxi_Trip_Data.csv` file, resample the data to an hourly frequency based on the dropoff time. Calculate the total `trip_distance`, `fare_amount`, `tolls_amount`, and `tip_amount`, then find the 5 hours with the most tips. # In[ ]: # --- # # ### Section 3 # # #### Exercise 3.1 # ##### Using the TSA traveler throughput data in the `tsa_melted_holiday_travel.csv` file, create box plots for traveler throughput for each year in the data. Hint: Pass `kind='box'` into the `plot()` method to generate box plots. # In[ ]: # #### Exercise 3.2 # ##### Using the TSA traveler throughput data in the `tsa_melted_holiday_travel.csv` file, create a heatmap that shows the 2019 TSA median traveler throughput by day of week and month. # In[ ]: # #### Exercise 3.3 # ##### Annotate the medians in the box plot from *[Exercise 3.1](#Exercise-3.1)*. Hint: The `x` coordinates will be 1, 2, and 3 for 2019, 2020, and 2021, respectively. Alternatively, to avoid hardcoding values, you can use the `Axes.get_xticklabels()` method, in which case you should look at the [documentation](https://matplotlib.org/stable/api/text_api.html) for the `Text` class. # In[ ]: