Adding duration categories
Now that you've set up the categories and values you want to capture, it's time to build a new column to analyze the frequency of flights by duration!
The variables flight_categories, short_flights, medium_flights, and long_flights that you previously created are available to you.
Additionally, the following packages have been imported: pandas as pd, numpy as np, seaborn as sns, and matplotlib.pyplot as plt.
This exercise is part of the course
Exploratory Data Analysis in Python
Exercise instructions
- Create
conditions, a list containing subsets ofplanes["Duration"]based onshort_flights,medium_flights, andlong_flights. - Create the
"Duration_Category"column by calling a function that accepts yourconditionslist andflight_categories, setting values not found to"Extreme duration". - Create a plot showing the count of each category.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create conditions for values in flight_categories to be created
conditions = [
(planes["____"].____.____(____)),
(planes["____"].____.____(____)),
(planes["____"].____.____(____))
]
# Apply the conditions list to the flight_categories
planes["Duration_Category"] = ____.____(____,
____,
default="____")
# Plot the counts of each category
sns.____(data=____, x="____")
plt.show()