<Python, pandas> Nanã®ããè¡ã鏿ãããNanãªãè¡ã鏿ããã
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]: pd.isnull(df) Out[36]: a b 0 False True 1 False False 2 True False 3 False True 4 False False
ã§ãï¼åã.any(axis=1)
ã§ï¼ã¤ã«åºãã¦ã
In [37]: df.isnull().any(axis=1) Out[37]: 0 True 1 False 2 True 3 True 4 False dtype: bool
ã§ããã¼ã¿ãã¬ã¼ã DataFrame
ã«æ¸¡ãã
In [38]: df[df.isnull().any(axis=1)] Out[38]: a b 0 1 NaN 2 NaN 3 3 3 NaN
ãªãã»ã©ã
ãã¨ããã®éã®.dropna()
In [39]: df.dropna() Out[39]: a b 1 2 2 4 4 5 In [40]: df.dropna(subset=['a']) Out[40]: a b 0 1 NaN 1 2 2 3 3 NaN 4 4 5