添加时长类别
既然您已经设定了要捕捉的类别和取值,现在就来构建一个新列,用于按航班时长分析频数吧!
您之前创建的变量 flight_categories、short_flights、medium_flights 和 long_flights 已可直接使用。
另外,以下包已导入:pandas 作为 pd,numpy 作为 np,seaborn 作为 sns,以及 matplotlib.pyplot 作为 plt。
本练习是课程的一部分
Python 中的探索性数据分析
练习说明
- 创建
conditions,其中包含基于short_flights、medium_flights和long_flights对planes["Duration"]的子集筛选结果。 - 通过调用一个可接收您的
conditions列表与flight_categories的函数来创建"Duration_Category"列,将未匹配到的值设为"Extreme duration"。 - 绘制一个图,显示各类别的计数。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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()