Pandas 결측치 최빈값으로 채우기

1 개요[ | ]

Pandas 결측치 최빈값으로 채우기
from io import StringIO
import pandas as pd
csv = """
Class  Name English Math
    A Alice      90   60
    A   Bob      80   NA
    A Carol      NA   80
    B  Dave      NA   60
   NA Erwin      90   50
"""
df = pd.read_csv(StringIO(csv),sep='\s+')
df
# 모든 컬럼 결측치를 각 컬럼의 최빈값으로 채우기
df.fillna(df.mode().iloc[0])
# 특정 컬럼(문자열) 결측치를 그 컬럼의 최빈값으로 채우기
df["Class"].fillna(df["Class"].mode()[0])
# 특정 컬럼(수치형) 결측치를 그 컬럼의 최빈값으로 채우기
df["English"].fillna(df["English"].mode()[0])

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}