In the following steps, we will validate a set of data that's been loaded from CSV using the Cerberus package:
- First, we need to build a schema that describes the data we expect. To do this, we must define a simple schema for floating-point numbers:
float_schema = {"type": "float", "coerce": float, "min": -1.0,
"max": 1.0}
- Next, we build the schema for individual items. These will be the rows of our data:
item_schema = {
"type": "dict",
"schema": {
"id": {"type": "string"},
"number": {"type": "integer", "coerce": int},
"lower": float_schema,
"upper": float_schema,
}
}
- Now, we can define the schema for the whole document, which will contain a list of items: ...