フライト時間のカテゴリを追加する
取得したいカテゴリと値の準備ができたので、フライト時間ごとの頻度を分析するための新しい列を作成しましょう。
これまでに作成した変数 flight_categories、short_flights、medium_flights、long_flights が利用できます。
さらに、次のパッケージがインポート済みです:pandas は pd、numpy は np、seaborn は sns、matplotlib.pyplot は plt。
この演習はコースの一部です
Pythonで学ぶ探索的データ分析
演習の手順
short_flights、medium_flights、long_flightsに基づいて、planes["Duration"]の部分集合を含むリストconditionsを作成します。conditionsリストとflight_categoriesを受け取る関数を呼び出し、見つからない値は"Extreme duration"に設定して、列"Duration_Category"を作成します。- 各カテゴリの件数を示すプロットを作成します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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()