Cleaning and validating data

‘Garbage in, garbage out’ is a stark reminder that it is almost impossible to draw meaningful insights from poor-quality data. Whilst there are highly regulated, safety-critical sectors in which data is routinely checked at every stage, the general standard of data validation in most analytical projects tends to be rather low.

However, if we write code to analyse data without first checking it, some results will be misleading, incorrect or invalid. The same applies if we fail to validate our output. In doing so, we end up contributing to the very ‘bad data’ that we all rail against. Postel’s Law – the principle of robustness proposed in the TCP standard – is helpful here:

“be conservative in what you do, be liberal in what you accept from others.” [1]

This stands in stark contrast to one of Python’s principles:

“Errors should never pass silently.” [2]

The XML specification also requires that malformed XML documents be rejected:

“„Validating and non-validating processors alike MUST report violations of this specification’s well-formedness constraints … that they read.”* [3]

The sections on Testing procedures, Value ranges and Regression testing do not require any prior knowledge of Python and are therefore generally suitable for professionals in the fields of data management, business management and quality assurance.

We will then provide you with a practical overview of various libraries and methods for data cleaning and validation using Python.