開始使用免費開始

加入飛行時長類別

既然你已經設定好想要標記的類別與值,接下來就來建立一個新的欄位,用來分析各種飛行時長的班次頻率吧!

你先前建立的變數 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()
編輯並執行程式碼