멀티 인덱스 Series에서 선택하기
여러 열에 대해 단일 .groupby() 연산을 수행하면 멀티 인덱스를 가진 Series가 생성됩니다. 이 객체를 다루는 방법은 DataFrame을 다루는 것과 비슷해요:
- 바깥 인덱스 수준은 DataFrame의 행과 비슷합니다.
- 안쪽 인덱스 수준은 DataFrame의 열과 비슷합니다.
이 연습 문제에서는 .loc[] 접근자를 사용해 멀티 인덱스 Series에서 데이터를 조회하는 연습을 합니다.
이 연습은 강의의 일부입니다
pandas로 경찰 활동 분석하기
연습 안내
- 직전 연습 문제의
.groupby()연산 결과를 새 객체arrest_rate로 저장하세요. (이미 수행해 두었습니다.) arrest_rateSeries를 출력해 살펴보세요.- 악천후에서 발생한 moving violation의 체포율을 출력하세요.
- 세 가지 모든 날씨 조건에서 발생한 speeding violation의 체포율을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Save the output of the groupby operation from the last exercise
arrest_rate = ri_weather.groupby(['violation', 'rating']).is_arrested.mean()
# Print the 'arrest_rate' Series
print(____)
# Print the arrest rate for moving violations in bad weather
print(____)
# Print the arrest rates for speeding violations in all three weather conditions
print(____)