불리언 인덱싱과 Matplotlib 즐기기
이제 불리언 인덱싱이 몇 줄의 코드만으로도 데이터를 시각적으로 탐색하는 데 어떻게 도움이 되는지 살펴보겠습니다. 이번 연습에서는 지금까지 배운 내용을 종합해 봅니다. 딕셔너리 데이터를 사용 가능한 pandas DataFrame으로 변환하고, 불리언으로 인덱싱한 뒤, matplotlib으로 데이터를 시각화해 wildlife strikes 데이터에서의 몇 가지 관계를 알아보세요.
이 연습은 강의의 일부입니다
MATLAB 사용자를 위한 Python
연습 안내
strikes딕셔너리를 DataFrame으로 변환하세요.'Engine'열에서'Turbofan'에 대한 불리언 필터를 만드세요.'Engine'열에서'Turboprop'에 대한 불리언 필터를 만드세요.turbofan과turboprop을 사용해strikes데이터셋을 필터링하여 산점도 두 개를 그리세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create a dictionary and then a DataFrame from the dictionary
strikes = {'Date': date,'Speed': speed,'Height':height,'Engine':engine}
strikes = pd.____(strikes)
# Filter strikes by engine type
turbofan = strikes['Engine']=='____'
turboprop = strikes['____']=='____'
# Create scatter plot of speed and height for each engine type
plt.scatter(strikes[____]['Speed'],strikes[____]['Height'],label='Turbofan')
plt.scatter(strikes[____]['Speed'],strikes[____]['Height'],label='Turboprop')
plt.legend()
plt.xlabel('Strike speed (knots)')
plt.ylabel('Strike height (feet)')
plt.show()