Welcome to the final module of Basic Data Transformation!
Imagine a school is preparing examination results for 500 students. Before publishing the results, the school discovers that some students have missing registration numbers, some scores are above 100, and some students have duplicate records.
These are examples of data quality problems.
Before using data for reports, analysis, or decision-making, we must check whether the information is correct and follows the required rules.
By the end of this module, you should be able to:
Data validation is the process of checking whether information follows specific rules before accepting or using it.
Think about a school registration form. The school may require:
If a student enters an examination score of 250, the system should identify it as invalid because the highest possible score is 100.
| Student | Age | Score | Status |
|---|---|---|---|
| Ada | 15 | 85 | Valid |
| Musa | 17 | 70 | Valid |
| Tunde | 14 | 150 | Invalid |
| Grace | -5 | 60 | Invalid |
Tunde's score is too high, while Grace's age is outside the school's allowed range.
Incorrect data can produce incorrect reports and decisions.
Imagine a company wants to calculate how much money it received from customers in one month. If some payment records contain incorrect amounts, the financial report may be wrong.
Data validation helps to:
Remember: Good data produces more reliable results.
A required field must not be empty.
For example, a school may require every student to provide a full name.
| Student Name | Status |
|---|---|
| Aisha Bello | Valid |
| Daniel Okafor | Valid |
| Empty | Invalid |
A data type rule checks whether information is stored in the correct format.
If someone enters "Fifteen" in a field that expects a number, the system may reject it.
Range validation checks whether a value falls within an allowed range.
Example: A school examination score must be between 0 and 100.
| Student | Score | Status |
|---|---|---|
| John | 75 | Valid |
| Mary | 100 | Valid |
| Peter | 120 | Invalid |
| David | -10 | Invalid |
Length validation checks how many characters a value contains.
For example, a school registration number may be required to contain exactly 8 characters.
The exact length depends on the organisation's rules.
Sometimes a field should only accept specific values.
For example, a school may allow only these examination statuses:
If a record contains "Excellent" in the examination status field, it does not follow the school's allowed values.
Uniqueness validation ensures that certain values do not appear more than once.
For example, every student should have a unique registration number.
| Student | Registration Number |
|---|---|
| Ada | CRM001 |
| Musa | CRM002 |
| Tunde | CRM003 |
| Grace | CRM002 |
Grace and Musa have the same registration number. This should be investigated using the school's official records.
Date validation checks whether dates follow an acceptable format and represent real calendar dates.
Examples of valid dates include:
However, 35/15/2026 is not a valid calendar date.
Consistency validation checks whether related information agrees.
For example, a student's date of birth indicates that the student is 15 years old, but the age field says 35. These two values do not agree and should be reviewed.
Data validation is one part of data quality management. Data quality checks help us determine whether a dataset is suitable for use.
| Characteristic | Meaning |
|---|---|
| Accuracy | Information correctly represents reality. |
| Completeness | Important information is available. |
| Consistency | Related information agrees. |
| Validity | Data follows required rules. |
| Uniqueness | Unwanted duplicates are avoided. |
| Timeliness | Information is up to date. |
Imagine a company has a customer database. Some customers have missing phone numbers, some phone numbers appear twice, and some addresses are outdated. The company needs to check and improve its records before using them for customer communication.
Python can help us check whether information follows specific rules.
students = [
{"name": "Ada", "score": 85},
{"name": "Musa", "score": 70},
{"name": "Tunde", "score": 150},
{"name": "Grace", "score": -5}
]
print(students)
The valid score range is 0 to 100.
for student in students:
score = student["score"]
if 0 <= score <= 100:
print(student["name"], "has a valid score")
else:
print(student["name"], "has an invalid score")
What does this code do?
for checks each student one after another.score collects the student's examination score.if checks whether the score is between 0 and 100.else displays a message when the score is outside the allowed range.Ada has a valid score
Musa has a valid score
Tunde has an invalid score
Grace has an invalid score
A student's name should not be empty. Let's create a simple validation rule.
students = [
{"name": "Ada", "age": 15},
{"name": "", "age": 16},
{"name": "Musa", "age": 17}
]
for student in students:
if student["name"].strip() == "":
print("Student name is missing")
else:
print(student["name"], "is valid")
The strip() function removes unnecessary spaces at the beginning and end of text. A name containing only spaces will also be identified as missing.
Let's assume a school accepts students between 10 and 25 years old.
ages = [15, 18, 30, -2, 12]
for age in ages:
if 10 <= age <= 25:
print(age, "is a valid age")
else:
print(age, "is an invalid age")
15 is a valid age
18 is a valid age
30 is an invalid age
-2 is an invalid age
12 is a valid age
Every student should have a unique registration number.
registration_numbers = [
"CRM001",
"CRM002",
"CRM003",
"CRM002"
]