Bắt đầu ngayBắt đầu miễn phí

Adding duration categories

Now that you've set up the categories and values you want to capture, it's time to build a new column to analyze the frequency of flights by duration!

The variables flight_categories, short_flights, medium_flights, and long_flights that you previously created are available to you.

Additionally, the following packages have been imported: pandas as pd, numpy as np, seaborn as sns, and matplotlib.pyplot as plt.

Bài tập này là một phần của khóa học

Exploratory Data Analysis in Python

Xem khóa học

Hướng dẫn bài tập

  • Create conditions, a list containing subsets of planes["Duration"] based on short_flights, medium_flights, and long_flights.
  • Create the "Duration_Category" column by calling a function that accepts your conditions list and flight_categories, setting values not found to "Extreme duration".
  • Create a plot showing the count of each category.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

# 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()
Chỉnh sửa và Chạy Mã