Checking DataFrame missing values

cols_missing = frame.columns[frame.isna().any()]
asset_img missing_value

Checking Series missing values

series.isna().any()

has_missing method

from loguru import logger
import pandas as pd
from pandas.core.frame import DataFrame
from pandas.core.series import Series
import traceback


def has_missing(self, values):
    """Check whether values have missing value.
    """
    if isinstance(values, DataFrame):
        cols_missing = values.columns[values.isna().any()]
        if not cols_missing.empty:
            logger.warning(f'The columns {", ".join(cols_missing)} contain missing values!' +
                           ''.join(traceback.format_stack()))
        return
    if isinstance(values, Series):
        if values.isna().any():
            logger.warning(f'The {Series.name} Series contain missing values! \n' +
                           ''.join(traceback.format_stack()))
        return
    raise ValueError('The argument values requires a DataFrame or a Series.')

Share on: TwitterFacebookEmail

Comments


Related Posts


Published

Category

Programming

Tags

Contact