Skip to content
ComputerCS
Start learning

Data Analytics · Lesson 5.2.1–5.2.3

Data Collection, Preparation, Cleaning and Transformation

Plan a useful data collection process, recognise data quality problems, clean records and transform raw data into an analysis-ready dataset.

01

Learning objectives

  • Distinguish population, sample, observation and variable.
  • Identify missing, duplicate, inconsistent and invalid values.
  • Explain why collection method and sampling bias affect conclusions.
  • Describe cleaning and transformation steps before analysis.
  • Describe the independent, dependent and controlled variables in a simple experiment and explain why a control or baseline can be useful.
02

Lesson notes

Data analytics starts with a question, not with a chart. Define the population you want to understand, select an appropriate sample, choose variables and decide how measurements will be collected. A census measures every member of a population; a sample measures a subset. A poorly selected sample can produce biased results even when calculations are flawless.

Data quality includes accuracy, completeness, consistency, validity and timeliness. A dataset may contain missing values, duplicated rows, inconsistent units, spelling variations, impossible dates or values outside the accepted range. Cleaning identifies these issues and applies documented rules instead of silently deleting inconvenient observations.

Transformation makes data suitable for analysis. Typical steps include parsing dates, standardising units, trimming text, converting numeric fields, deriving new variables and grouping categories. Keep the raw source unchanged where possible, record each transformation and retain enough information to reproduce the process.

The handling of missing or unusual values depends on their cause and the research question. Deleting every incomplete row can bias results if missingness is not random. Replacing values with a mean can hide variation. Record the chosen policy, inspect the effect and communicate limitations with the final result.

Experimental design plans how an investigation will test a question. Identify the research question, independent variable (the factor deliberately changed), dependent variable (the outcome measured), controlled variables (factors kept as consistent as possible), participants or sample, procedure and method of recording results. A control group or baseline can help compare outcomes. A fair experiment changes the factor being studied while keeping other important conditions consistent. Repeat measurements where practical, document limitations and avoid claiming causation from a simple observational survey.

03

Worked code examples

Worked example

The transformation trims whitespace, removes the repeated row and flags a non-numeric age for review rather than treating it as a number.

raw = [" Ali , 18 ", "Sara,17", "Ali, 18", "Hina,not-known"]
clean = []
for row in raw:
    name, age = [part.strip() for part in row.split(",")]
    if age.isdigit():
        clean.append({"name": name, "age": int(age)})
print(clean)
Output
[{'name': 'Ali', 'age': 18}, {'name': 'Sara', 'age': 17}]
04

Key terminology

Population

The complete group a study aims to understand.

Sample

A subset of the population selected for observation.

Missing value

A field for which no usable observation is available.

Data cleaning

Finding and correcting or documenting quality problems in data.

Independent variable

The factor deliberately changed or compared in an experiment.

Dependent variable

The outcome measured in response to the independent variable.

Controlled variable

A factor kept consistent so that the experiment is a fair comparison.

05

Common misconceptions

Common mistake

A large sample is automatically representative.

Correct understanding

Representativeness depends on sampling method and coverage, not only sample size.

Common mistake

Cleaning means deleting every unusual value.

Correct understanding

Unusual values require investigation; some are valid observations and should be retained.

06

Check your understanding

1. Which problem describes the same record appearing twice?

2. Why preserve the raw dataset?

3. A biased sample can lead to:

4. In an experiment testing how study time affects quiz scores, what is the dependent variable?

NERDLYY · FEEDBACK

Help shape Nerdlyy

Your feedback goes directly to the team. We read every submission.

No reply needed — you can send feedback without sharing contact details.