Dask bag 필터링
여러 출처에서 수집된 정치인 데이터라서 데이터가 깔끔하지 않아요. 분석에 필요한 키가 빠진 딕셔너리가 많습니다. 중요한 키가 누락된 요소는 걸러내야 해요.
환경에는 has_birth_date()라는 함수가 준비되어 있어요. 이 함수는 입력 딕셔너리에 'birth_date' 키가 있는지 확인하며, 있으면 True, 없으면 False를 반환해요.
def has_birth_date(dictionary):
return 'birth_date' in dictionary
이전 연습 문제에서 만들었던 bag은 환경에 dict_bag으로 제공되어 있어요.
이 연습은 강의의 일부입니다
Python에서 Dask로 병렬 프로그래밍
연습 안내
dict_bag의.count()메서드를 사용해 포함된 요소의 개수를 출력하세요.has_birth_date()함수를 사용해'birth_date'키가 없는 요소를 걸러내세요.filtered_bag에 들어 있는 요소의 개수를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Print the number of elements in dict_bag
print(____)
# Filter out records using the has_birth_date() function
filtered_bag = dict_bag.____(____)
# Print the number of elements in filtered_bag
print(____)