始める無料で始める

フライト時間のカテゴリを追加する

取得したいカテゴリと値の準備ができたので、フライト時間ごとの頻度を分析するための新しい列を作成しましょう。

これまでに作成した変数 flight_categoriesshort_flightsmedium_flightslong_flights が利用できます。

さらに、次のパッケージがインポート済みです:pandaspdnumpynpseabornsnsmatplotlib.pyplotplt

この演習はコースの一部です

Pythonで学ぶ探索的データ分析

コースを見る

演習の手順

  • short_flightsmedium_flightslong_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()
コードを編集して実行