연산 연결하기
이제 데이터를 불러오고 정리했으니, 분석을 시작해 보겠습니다. 첫 과제로 정치인의 생년월일을 살펴보세요. 생년월일은 'YYYY-MM-DD' 형태의 문자열이며, 문자열의 처음 4자리가 연도입니다.
이전 연습 문제에서 만든 필터링된 Dask bag인 filtered_bag이 환경에 준비되어 있습니다.
이 연습은 강의의 일부입니다
Python에서 Dask로 병렬 프로그래밍
연습 안내
- bag의
.pluck()메서드를 사용해'birth_date'문자열을 추출하세요. - 람다 함수를 작성해
'birth_date'문자열에서 연도 문자열을 추출하고 정수로 변환하세요. - 새로운 bag
birth_year_bag을 사용해 출생 연도의 최솟값, 최댓값, 평균을 계산하세요. dask.compute()함수를 사용해 세 가지 집계를 효율적으로 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Select the 'birth_date' from each dictionary in the bag
birth_date_bag = filtered_bag.____
# Extract the year as an integer from the birth_date strings
birth_year_bag = birth_date_bag.____(lambda x: ____)
# Calculate the min, max and mean birth years
min_year = ____
max_year = ____
mean_year = ____
# Compute the results efficiently and print them
print(____(____))