비행시간 범주 추가하기
이제 찾으려는 값과 범주를 설정했으므로, 비행시간별 항공편 빈도를 분석할 새로운 열을 만들어 보겠습니다!
이전에 생성한 변수인 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리스트와"Duration_Category"를 받는 함수를 호출하여flight_categories열을 생성하되, 조건과 일치하지 않는 값은"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()