开始使用免费开始使用

添加时长类别

既然您已经设定了要捕捉的类别和取值,现在就来构建一个新列,用于按航班时长分析频数吧!

您之前创建的变量 flight_categoriesshort_flightsmedium_flightslong_flights 已可直接使用。

另外,以下包已导入:pandas 作为 pdnumpy 作为 npseaborn 作为 sns,以及 matplotlib.pyplot 作为 plt

本练习是课程的一部分

Python 中的探索性数据分析

查看课程

练习说明

  • 创建 conditions,其中包含基于 short_flightsmedium_flightslong_flightsplanes["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()
编辑并运行代码