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

잔글 (Jmnote님이 Pandas 결측치 특정 값으로 채우기 문서를 Pandas 결측치 특정값으로 채우기 문서로 이동했습니다)
16번째 줄: 16번째 줄:
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
<syntaxhighlight lang='python' notebook>
# 전체 결측치를 0으로 채우기
# 모든 컬럼의 결측치를 0으로 채우기
df.fillna(0)
df.fillna(0)
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
<syntaxhighlight lang='python' notebook>
# 전체 결측치를 missing으로 채우기
# 모든 컬럼의 결측치를 missing으로 채우기
df.fillna("missing")
df.fillna("missing")
</syntaxhighlight>
</syntaxhighlight>

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

1 개요

Pandas 결측치 특정 값으로 채우기
from io import StringIO
import pandas as pd
csv = """
Class  Name English Math
    A Alice      90   60
    A   Bob      80   NA
    B Carol      NA   80
    B  Dave      60   90
"""
df = pd.read_csv(StringIO(csv),sep='\s+')
df
# 모든 컬럼의 결측치를 0으로 채우기
df.fillna(0)
# 모든 컬럼의 결측치를 missing으로 채우기
df.fillna("missing")
# 특정 컬럼의 결측치를 0으로 채우기
df2 = df.copy()
df2["Math"].fillna(0, inplace=True)
df2
# 특정 컬럼의 결측치를 missing으로 채우기
df2 = df.copy()
df2["Math"].fillna("missing", inplace=True)
df2

2 같이 보기

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