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.
Bài tập này là một phần của khóa học
Exploratory Data Analysis in Python
Hướng dẫn bài tập
- 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.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
# 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()