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

 
(같은 사용자의 중간 판 2개는 보이지 않습니다)
11번째 줄: 11번째 줄:
     A Carol      NA  80
     A Carol      NA  80
     B  Dave      NA  90
     B  Dave      NA  90
     B Erwin      60  90
     B Erwin      60  80
"""
"""
df = pd.read_csv(StringIO(csv),sep='\s+')
df = pd.read_csv(StringIO(csv),sep='\s+')
26번째 줄: 26번째 줄:
<syntaxhighlight lang='python' notebook>
<syntaxhighlight lang='python' notebook>
# 특정 컬럼의 결측치를 0으로 채우기
# 특정 컬럼의 결측치를 0으로 채우기
df["Math"].fillna(0)
df["English"].fillna(0)
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='python' notebook>
<syntaxhighlight lang='python' notebook>

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 }}