Untitled

mail@pastecode.io avatar
unknown
python
a year ago
791 B
4
Indexable
Never
import pandas as pd
from loguru import logger


class DataValidationProcessor:
    def __init__(self, csv_file, usecols):
        self.df = pd.read_csv(csv_file, usecols=usecols)

    def validate_data(self):
        if self.df.isnull().values.any():
            raise Exception("Null values found")
            
        non_numeric = [col for col in self.df.columns if not self.df[col].dtype in [int, float]]
        if non_numeric:
            raise Exception("Non numeric columns found: " + ", ".join(non_numeric))

        invalid_names = [col for col in self.df.columns if ' ' in col] 
        if invalid_names:
            raise Exception("Invalid column names found: " + ", ".join(invalid_names))
            
        logger.info("CSV data validation passed!")
        return self.df