始める無料で始める

所要時間カテゴリの追加

カテゴリと取得したい値の設定が済んだので、次は新しい列を作成して、所要時間ごとのフライトの出現回数を分析しましょう。

前の手順で作成した変数 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()
コードを編集して実行