시작하기무료로 시작하기

날씨 조건 평가하기

이전 연습 문제에서는 하루마다 나쁜 날씨 조건의 개수를 셌습니다. 이번에는 그 개수를 활용해 날씨 평가(rating) 체계를 만들어 보려 합니다.

개수 범위는 0부터 9까지이며, 다음과 같이 평가로 변환하세요:

  • 0'good'
  • 1부터 4'bad'
  • 5부터 9'worse'

이 연습은 강의의 일부입니다

pandas로 경찰 활동 분석하기

강의 보기

연습 안내

  • bad_conditions 열의 고유값을 세고 인덱스를 정렬하세요. (이미 수행되어 있습니다.)
  • mapping이라는 딕셔너리를 만들어 bad_conditions 정수를 지정된 문자열로 매핑하세요.
  • mapping을 사용해 bad_conditions의 정수를 문자열로 변환하고, 결과를 rating이라는 새 열에 저장하세요.
  • rating의 고유값을 세어 정수가 문자열로 올바르게 변환되었는지 확인하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Count the unique values in 'bad_conditions' and sort the index
print(weather.bad_conditions.value_counts().sort_index())

# Create a dictionary that maps integers to strings
mapping = {0:'good', 1:'bad', 2:'bad', ____}

# Convert the 'bad_conditions' integers to strings using the 'mapping'
weather['rating'] = weather.bad_conditions.____

# Count the unique values in 'rating'
print(____)
코드 편집 및 실행