๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Python/Pandas

[Python] Pandas - Dataframe, NaN ๊ฐฏ์ˆ˜

๋ฐ˜์‘ํ˜•
def cnt_nan(df):
    """์ „์ฒด ํ–‰ NaN ๊ฐฏ์ˆ˜ ์กฐํšŒ
    
    :param pandas.DataFrame df: dataframe
    
    :return: dataframe
    
    Example:
        ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์„ธ์š”:
        
        >>> cnt_nan(df)
    """
    df_len = len(df)
    df = pd.DataFrame(df.isnull().sum())
    df['%'] = (df[0]/df_len)*100 # ๋น„์œจ
    df = df.rename(columns = {0: 'NaN cnt'})
    
    return df

 

๋ฐ˜์‘ํ˜•