Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work. Try for free Learn more
pandas.DataFrame, Seriesに欠損値NaNが含まれているか判定する方法、および、欠損値NaNの個数をカウントする方法について説明する。isnull(), isna(), notnull(), notna()メソッドなどを使う。 欠損値NaNを削除・置換する方法、欠損値NaNに限らず特定の条件を満たす要素の数をカウントする方法については以下の記事を参照。 関連記事: pandasで欠損値NaNを削除(除外)するdropna 関連記事: pandasで欠損値NaNを置換(穴埋め)するfillna 関連記事: pandasで特定の条件を満たす要素数をカウント(全体、行・列ごと) なお、pandasではNaN(Not a Number: 非数)のほか、Noneも欠損値として扱われる。 関連記事: pandasにおける欠損値(nan, None, pd.NA) 本記事のサンプルコ
Nanのある行、ない行を選択する。 .isnull()と.dropna()。 お互いが逆だが、返す値がちと違う。 まずは、Nanのある行を選択。 In [31]: import pandas as pd In [32]: import numpy as np In [33]: df = pd.DataFrame({'a':[1,2,np.nan,3,4],'b':[np.nan,2,3,np.nan,5]}) In [34]: df Out[34]: a b 0 1 NaN 1 2 2 2 NaN 3 3 3 NaN 4 4 5 In [35]: df.isnull() Out[35]: a b 0 False True 1 False False 2 True False 3 False True 4 False False と、boolで返る。 また、下記でも同じ。 In [36]:
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く