데이터 타입 확인하기
데이터의 시대에는 과거보다 훨씬 더 많은 속성에 접근할 수 있어요. 이를 처리하려면 많은 자동화가 필요하지만, 최소한 각 속성의 데이터 타입이 올바른지는 확인해야 합니다. 이 연습에서는 속성과 그 데이터 타입으로 이루어진 딕셔너리의 유효성을 검사해 올바른지 확인해 보겠습니다. 이 딕셔너리는 validation_dict 변수에 저장되어 있으며 작업 공간에 준비되어 있어요.
이 연습은 강의의 일부입니다
PySpark로 하는 Feature Engineering
연습 안내
df의dtypes를 사용해 속성명과 데이터 타입의 튜플 리스트를 만들고, 변수 이름을actual_dtypes_list로 지정하세요.actual_dtypes_list를 반복(iterate)하면서, 각 열 이름이 예상 데이터 타입 딕셔너리validation_dict에 존재하는지 확인하세요.- 딕셔너리에 존재하는 키에 대해서는 데이터 타입을 비교하고, 일치하는 항목을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# create list of actual dtypes to check
actual_dtypes_list = df.____
print(actual_dtypes_list)
# Iterate through the list of actual dtypes tuples
for attribute_tuple in ____:
# Check if column name is dictionary of expected dtypes
col_name = attribute_tuple[____]
if col_name in ____:
# Compare attribute types
col_type = attribute_tuple[____]
if col_type == validation_dict[____]:
print(col_name + ' has expected dtype.')