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

(새 문서: ==개요== ;Pandas 결측치 특정 값으로 채우기 <syntaxhighlight lang='python' notebook> from io import StringIO import pandas as pd csv = """ Class Name English Math A...)
 
 
(같은 사용자의 중간 판 9개는 보이지 않습니다)
9번째 줄: 9번째 줄:
     A Alice      90  60
     A Alice      90  60
     A  Bob      80  NA
     A  Bob      80  NA
     B Carol      NA  80
     A Carol      NA  80
     B  Dave      60  90
     B  Dave     NA  90
    B Erwin     60  80
"""
"""
df = pd.read_csv(StringIO(csv),sep='\s+')
df = pd.read_csv(StringIO(csv),sep='\s+')
16번째 줄: 17번째 줄:
</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["English"].fillna("missing")
df.fillna("missing")
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
# 특정 컬럼의 결측치를 0으로 채우기
df["English"].fillna(0)
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
# 특정 컬럼의 결측치를 missing으로 채우기
df["Math"].fillna("missing")
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[Pandas fillna()]]
* [[Pandas fillna()]]
* [[Pandas 결측치 채우기]]


[[분류: Pandas 결측치]]
[[분류: Pandas 결측치]]

2022년 1월 18일 (화) 03:48 기준 최신판

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

2 같이 보기[ | ]

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