Clean pandas dataframe using pandera validation. The returned dataframe is the result of droping non-valid records.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pandera as pa | |
def clean_dataframe_with_schema(dataframe, schema): | |
try: | |
return schema.validate(dataframe) | |
except (pa.errors.SchemaErrors, pa.errors.SchemaError) as err: | |
return dataframe.drop(labels=err.failure_cases['index'].to_list()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment