ADP/실기

데이터프레임에 함수 적용

hyerimir 2024. 1. 21. 17:49
# apply : 행 또는 열 방향으로 주어진 함수를 한 번에 적용

# 두 개의 열 중에 큰 값이 선택되도록 하기
df_sejong[['전용면적(m^2)', '보증금(만원)']].apply(np,max, axis = 1)
# map(lambda) : 데이터 내부 각 요소를 처리하는 함수
data['col_name'] = data['col_name'].map(lambda x : x.func(), na_action = 'ignore')

# lambda는 간단한 함수 개념
# map(lambda)를 사용할 때에는 시리즈 형식이어야 함
# map은 원소 접근이어야 함
df_sejong['시군구'].map(lambda x : x.split(" "))
# map은 원소 접근이므로, str.split가 아닌 .split를 써야함

df_sejong['계약년월'].map(labmda x : str(x)[0:4])