"Pandas 결측치 특정값으로 채우기"의 두 판 사이의 차이

26번째 줄: 26번째 줄:
<syntaxhighlight lang='python' notebook>
<syntaxhighlight lang='python' notebook>
# 특정 컬럼의 결측치를 0으로 채우기
# 특정 컬럼의 결측치를 0으로 채우기
df["Math"].fillna(0)
df["English"].fillna(0, inplace=True)
df
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
<syntaxhighlight lang='python' notebook>
# 특정 컬럼의 결측치를 missing으로 채우기
# 특정 컬럼의 결측치를 missing으로 채우기
df["Math"].fillna("missing")
df["Math"].fillna("missing", inplace=True)
df
</syntaxhighlight>
</syntaxhighlight>



2022년 1월 18일 (화) 03:44 판

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   90
    B Erwin      60   90
"""
df = pd.read_csv(StringIO(csv),sep='\s+')
df
# 모든 컬럼의 결측치를 0으로 채우기
df.fillna(0)
# 모든 컬럼의 결측치를 missing으로 채우기
df.fillna("missing")
# 특정 컬럼의 결측치를 0으로 채우기
df["English"].fillna(0, inplace=True)
df
# 특정 컬럼의 결측치를 missing으로 채우기
df["Math"].fillna("missing", inplace=True)
df

2 같이 보기

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