New
New
Year 11
AQA

Reading CSV files

I can read and structure data in a CSV file.

New
New
Year 11
AQA

Reading CSV files

I can read and structure data in a CSV file.

These resources will be removed by end of Summer Term 2025.

Switch to our new teaching resources now - designed by teachers and leading subject experts, and tested in classrooms.

These resources were created for remote use during the pandemic and are not designed for classroom teaching.

Lesson details

Key learning points

  1. CSV text files group data together on individual lines and separates values in these groups by commas.
  2. CSV files can be read by a range of different spreadsheet software packages as well as Python files.
  3. Each item is seperated by a comma, each record is seperated over a new row in the file.
  4. A CSV file is the same as any other text file where each row is stored as string.

Keywords

  • CSV - comma-separated values are a plaintext data file where each value is separated by a single comma

  • Tabular - displaying data in a grid of rows and columns

  • Strip() - a Python method which removes any leading, and trailing whitespaces or characters that you specify

  • Split() - a Python method which is used to break a string into a list based on a specified delimiter

Common misconception

It is not possible to interrogate a CSV file in Python without importing a specialised library.

A CSV file behaves in the same way as a txt file in Python. Data is read from the file as strings and methods can be used to remove extra characters like commas, spliting the values either side in to separate items.


To help you plan your year 11 computer science lesson on: Reading CSV files, download all teaching resources for free and adapt to suit your pupils' needs...

This lesson inlcudes sample programs with .csv files attached. If you are not using The Raspberry Pi Code Editor, you will need to make versions of these available locally for pupils to use.
Teacher tip

Equipment

All pupils requires access to devices that can edit and run Python programs. Starter code files are available to copy or use directly via the Raspberry Pi Code Editor.

Licence

This content is © Oak National Academy Limited (2025), licensed on Open Government Licence version 3.0 except where otherwise stated. See Oak's terms & conditions (Collection 2).

Lesson video

Loading...

6 Questions

Q1.
Which method reads the entire content of a file as a single string?
Correct answer: `read()`
readline()
fetch()
readlines()
Q2.
Match the operation to the description
Correct Answer:open(),opens a file for reading or writing

opens a file for reading or writing

Correct Answer:write(),adds content to a file and overwrites any existing data

adds content to a file and overwrites any existing data

Correct Answer:read(),reads the entire file as a string

reads the entire file as a string

Correct Answer:append(),adds content to the end of an existing file

adds content to the end of an existing file

Correct Answer:readline(),reads one line at a time

reads one line at a time

Q3.
What does the "w" mode do when opening a file?
appends new data to the file
Correct answer: opens the file for writing and overwrites existing content
opens the file in read-only mode
opens the file for writing without overwriting.
Q4.
Which method is used to free up system resources?
stop()
quit()
Correct answer: `close()`
end()
Q5.
What mode should be used to read a file without modifying it?
"w"
"a"
Correct answer: "r"
Q6.
What is the correct way to write multiple lines to a file in Python?
file.write(["line1", "line2"])
Correct answer: `file.writelines(["line1", "line2"])`
file.insert(["line1", "line2"])
file.append(["line1", "line2"])

6 Questions

Q1.
What does CSV stand for?
computer system variables
code syntax validation
Correct answer: comma-separated values
Q2.
Which Python method is used to remove leading and trailing spaces from a string?
trim()
Correct answer: `strip()`
split()
remove()
Q3.
What type of structure does a CSV file follow?
hierarchical format
graph format
Correct answer: tabular format
linear text format
Q4.
In a CSV file, each represents a new record.
Correct Answer: row
Q5.
The default delimiter in a CSV file is a .
Correct Answer: comma, ,
Q6.
Which Python method is used to break a string based on a specific delimiter?
strip()
slice()
Correct answer: `split()`
divide()