호칭 제거하고 이름 추출하기
airlines DataFrame에서 설문 응답자 메타데이터를 수집하는 동안, 응답자의 전체 이름이 full_name 열에 저장되었습니다. 그런데 자세히 보니 많은 이름 앞에 "Dr.", "Mr.", "Ms.", "Miss"와 같은 호칭이 붙어 있었습니다.
최종 목표는 응답자의 이름과 성을 각각 담은 first_name과 last_name이라는 두 개의 새 열을 만드는 것입니다. 그에 앞서, 먼저 호칭을 제거해야 합니다.
airlines DataFrame과 pandas는 pd로 여러분의 작업 환경에 준비되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 데이터 정제하기
연습 안내
full_name에서"Dr.","Mr.","Miss","Ms."를 해당 순서대로 빈 문자열""로 치환해 제거하세요..str.contains()를 사용한assert문을 실행하여full_name에 호칭이 여전히 남아 있는지 검사하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Replace "Dr." with empty string ""
airlines['full_name'] = airlines['full_name'].____.____("____","")
# Replace "Mr." with empty string ""
airlines['full_name'] = ____
# Replace "Miss" with empty string ""
____
# Replace "Ms." with empty string ""
____
# Assert that full_name has no honorifics
assert airlines['full_name'].str.contains('Ms.|Mr.|Miss|Dr.').any() == False