所要時間カテゴリの追加
カテゴリと取得したい値の設定が済んだので、次は新しい列を作成して、所要時間ごとのフライトの出現回数を分析しましょう。
前の手順で作成した変数 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を受け取る関数を使って、"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()