Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Basic Data Transformation ยท Lesson 6 of 9

Module Five

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
6
Module 5: Converting and Formatting Data

MODULE 5: CONVERTING AND FORMATTING DATA

Course: Basic Data Transformation

Module: 5 of 8

Level: Beginner

1. Introduction

Imagine you are a teacher in a secondary school in Ibadan. You have a spreadsheet containing students' examination scores.

Some scores are written as numbers, such as 85, while others are stored as text, such as "85".

Although they look similar, a computer may treat them differently. The number 85 can be used in calculations, but the text "85" may need to be converted before it can be used in mathematical operations.

This is why data conversion and formatting are important.

2. What Is Data Conversion?

Data conversion means changing data from one type or format into another.

Original Data Converted Data
"25" (Text)25 (Number)
"2026-11-24"24 November 2026
0.7575% (display format)
5000"5000" (Text)

Why Do We Convert Data?

  • To correct data stored in the wrong format.
  • To allow computers to perform calculations.
  • To make information easier to understand.
  • To prepare information for data analysis.
  • To make data compatible with other applications.

3. Understanding Common Data Types

A. Text (String)

Text contains letters, words, or characters.

"CRMNuggets"
"John"
"Computer Science"

In Python, text is called a string.

B. Integers

Integers are whole numbers without decimal points.

10
25
100
1500

C. Decimal Numbers (Floats)

These are numbers that contain decimal points.

12.5
45.75
99.9

D. Boolean Values

Boolean values represent two possibilities: True or False.

True
False

For example:

  • Has the student paid? True.
  • Has the student submitted the assignment? False.

4. Converting Text into Numbers

Sometimes numbers are stored as text. Python provides functions that help us convert them.

Using int()

The int() function converts suitable values into whole numbers.

age = "13"

new_age = int(age)

print(new_age)
print(type(new_age))

Output:

13
<class 'int'>

The value has changed from text into an integer.

Using float()

The float() function converts suitable values into decimal numbers.

price = "2500.50"

new_price = float(price)

print(new_price)

Output:

2500.5
Important: Not every text value can be converted into a number. For example, converting "Excellent" into an integer will produce an error because it is not a numeric value.

5. Converting Numbers into Text

Sometimes you need to convert a number into text. Python uses the str() function.

score = 85

message = "Your score is " + str(score)

print(message)

Output:

Your score is 85

This is useful when you want to combine numbers with messages. For example, a learning platform can display:

You earned 500 XP points.

6. Converting Data into Boolean Values

Python uses the bool() function to convert values into Boolean values.

payment = 1

result = bool(payment)

print(result)

Output:

True

Another example:

payment = 0

result = bool(payment)

print(result)

Output:

False

Generally, zero and empty values are treated as False, while most non-empty values are treated as True.

7. What Is Data Formatting?

Data formatting means changing how information is displayed without necessarily changing the original meaning or underlying value.

For example, the number 2500 can be displayed in different ways:

2500
2,500
โ‚ฆ2,500.00

They can represent the same amount of money, but their presentation is different.

A. Currency Formatting

Instead of displaying:

5000

You can display:

โ‚ฆ5,000.00

This makes it clear that the value represents Nigerian Naira.

B. Date Formatting

The same date can appear in different formats:

2026-11-24
24/11/2026
24 November 2026

C. Percentage Formatting

A decimal value such as 0.75 can be displayed as 75%.

D. Decimal Formatting

A value such as 45.67891 can be displayed with two decimal places:

45.68

8. Formatting Data in Excel and Google Sheets

You can convert and format data without writing Python code.

Example: Formatting Currency

StudentAmount Paid
Tunde5000
Amina3500
David7000

To format the amounts as Nigerian currency:

  1. Open your spreadsheet.
  2. Select the cells containing the amounts.
  3. Click the Number Format option.
  4. Choose Currency.
  5. Select Nigerian Naira if available.

Your spreadsheet can now display:

StudentAmount Paid
Tundeโ‚ฆ5,000.00
Aminaโ‚ฆ3,500.00
Davidโ‚ฆ7,000.00

Example: Formatting Dates

If your spreadsheet contains 2026-11-24, you can change its display format to 24 November 2026.

9. Practical Python Exercise: Converting Student Scores

A teacher has collected examination scores, but the scores are stored as text. Your task is to convert them into numbers and calculate the average.

scores = ["70", "85", "90", "65", "80"]

# Convert text scores into numbers
converted_scores = []

for score in scores:
    converted_scores.append(int(score))

# Calculate the total
total = sum(converted_scores)

# Calculate the average
average = total / len(converted_scores)

print("Converted Scores:", converted_scores)
print("Total Score:", total)
print("Average Score:", average)

Expected Output:

Converted Scores: [70, 85, 90, 65, 80]
Total Score: 390
Average Score: 78.0

What Did We Learn?

  • The original scores were stored as text.
  • We used int() to convert each score into a number.
  • We used sum() to calculate the total.
  • We used len() to count the scores.
  • We divided the total by the number of students to calculate the average.

10. Practical Activity: Transforming School Payment Data

Imagine you are helping a school administrator organise payment records. The payment amounts are stored as text.

StudentPayment
Tunde"5000"
Amina"3500"
David"7000"
Grace"4500"

Your Tasks

  1. Convert each payment amount into a number.
  2. Calculate the total amount collected.
  3. Calculate the average payment.
  4. Display the total with the label "Total School Payment".

Suggested Python Code:

payments = ["5000", "3500", "7000", "4500"]

converted_payments = []

for payment in payments:
    converted_payments.append(int(payment))

total = sum(converted_payments)

average = total / len(converted_payments)

print("Total School Payment:", total)
print("Average Payment:", average)

Expected Output:

Total School Payment: 20000
Average Payment: 5000.0

11. Common Mistakes to Avoid

Mistake 1: Converting Words into Numbers

You cannot directly convert "Good" into an integer.

Mistake 2: Confusing Formatting with Conversion

Displaying 5000 as โ‚ฆ5,000.00 does not necessarily change its underlying numeric value.

Mistake 3: Ignoring Decimal Values

Using int() on a decimal number removes the decimal part. For example, int(12.8) becomes 12.

Mistake 4: Forgetting to Check Your Data

Always check whether your data contains unexpected values before converting it.

12. Key Terms to Remember

TermMeaning
Data ConversionChanging data from one type or format to another.
Data FormattingChanging how data is displayed.
StringText data.
IntegerA whole number.
FloatA decimal number.
BooleanA True or False value.
int()Converts suitable values into integers.
float()Converts suitable values into decimal numbers.
str()Converts values into text.
bool()Converts values into Boolean values.

13. Module Summary

In this module, you learned that data conversion and formatting help computers and people work with information correctly.

You learned how to:

  • Convert text into numbers.
  • Convert numbers into text.
  • Convert values into Boolean data.
  • Format currency, dates, percentages, and decimal numbers.
  • Use Python to transform student scores and payment records.
  • Format information in Excel and Google Sheets.
Remember: Data conversion changes the data type or representation, while formatting changes how information is presented.

14. Module Assessment: Test Your Knowledge

Answer all 10 questions below to check what you have learned.

Next Module

Module 6: Combining and Merging Data

In the next module, you will learn how to bring information from different tables and datasets together to create more useful information.

CRMNuggets โ€“ Learn. Practice. Get Certified.

๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’