Explore Library
Code QuizAdvanced

Validating a DataFrame Schema

Find why a missing required column passes validation.

Codepython
def validate(df, schema):
    for col, dtype in schema.items():
        if col in df.columns:
            assert df[col].dtype == dtype, f'{col} wrong type'
    return True

# schema = {'user_id': 'int64', 'amount': 'float64'}

What is the bug in this schema validation?