DataFrame으로 변환하기
정치인 JSON 데이터로 DataFrame을 만들려고 합니다. 중첩 구조를 풀었으니, 이제 DataFrame의 열로 사용할 키만 선택하면 돼요.
이전 연습 문제에서 만든 Dask bag은 dict_bag라는 이름으로 환경에 제공되어 있어요.
이 연습은 강의의 일부입니다
Python에서 Dask로 병렬 프로그래밍
연습 안내
select_keys()함수를 완성해keys_to_keep목록의 키들을 새로운 필터링 딕셔너리에 추가하여 반환하세요.select_keys()함수를 사용해dict_bag에서['gender','name', 'birth_date', 'url']키를 선택하세요.- 필터링된 bag을 Dask DataFrame으로 변환하세요.
- DataFrame의 처음 몇 행을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
def select_keys(dictionary, keys_to_keep):
new_dict = {}
# Loop through kept keys and add them to new dictionary
for k in ____:
____
return new_dict
# Use the select_keys to reduce to the 4 required keys
filtered_bag = dict_bag.map(____, ____=____)
# Convert the restructured bag to a DataFrame
df = filtered_bag.____
# Print the first few rows of the DataFrame
print(____)