Sonzaschool
Back

O-Level · Form 4 · Vocational · Electronics and Computer

Computer Programming

Performing basic data transformations

about 5 minutes to read

Discussions
Topics in this sectionCleaning and organising data4 topics

Data transformation is the process of changing the structure, format, or values of data to make it more suitable for analysis. In data science and programming, we often need to clean, organize, and reshape our data before we can use it to answer questions or make decisions. This topic covers the basic techniques that every data analyst must know: filtering rows, sorting rows, renaming columns, and creating new calculated columns from existing data.

Filtering means selecting only the rows that meet certain conditions. When working with datasets, we often need to work with a subset of data that satisfies specific criteria.

To filter data in Python using pandas, we use conditions inside square brackets. For example, to select only rows where a column called price is greater than a certain value, we write:

filtered_data = data[data['price'] > 5000]

This reads as: "Give me rows from data where the price column is greater than 5000."

We can combine multiple conditions using:

  • & for AND (both conditions must be true)
  • | for OR (at least one condition must be true)

Example: selecting students who scored above 60 in both Mathematics and English:

passed = data[(data['math'] > 60) & (data['english'] > 60)]

How you'll be assessedProcess assessment · Outcome assessment · Knowledge assessment

Process assessment

  • Manipulate data structures and apply transformations like filtering and sorting.
  • Create meaningful derived variables.

Outcome assessment

A transformed dataset that meets specified requirements (e.g., sorted, filtered, or with additional features).

Knowledge assessment

Detailed knowledge of:

Method used: The student should explain how to:

  • apply transformations on data

Principles: The student should explain the principles of

  • Reproducibility in data transformations.

Theories: The student should explain:

  • Feature engineering and its role in improving data utility.

Circumstantial knowledge:

Detailed knowledge about:

  • Handling errors when performing complex transformations (e.g., applying functions to entire columns).

Question

Which pandas expression selects only rows where the age column is greater than 18?

Sign in to submit your answer and have it count toward your mastery.

Sign in to practice

Tutor

Stuck? Ask me anything about this topic.

Sign in to ask the Sonza AI Tutor about this question.

Sign in to ask

Discussions

No questions yet

Sign in to ask
Loading discussions…