Filter and Count CSV Rows
Advanced · Write the code · from Python CSV: Read, Write, and Process CSV Files
From the lesson: Python CSV: Read, Write, and Process CSV Files
Think about a spreadsheet with rows and columns - names in one column, ages in another, scores in a third. A CSV file (Comma-Separated Values) is just a plain text version of that spreadsheet, where commas separate each column.
Read the lessonGiven student grade data, count how many students scored 90 or above in the score column and print the result.
The CSV data:
name,score
Alice,95
Bob,72
Charlie,90
Diana,88
Eve,91Expected output:
High scorers: 3import csv
import io
data = 'name,score\nAlice,95\nBob,72\nCharlie,90\nDiana,88\nEve,91'
f = io.StringIO(data)
# Your code here
More CSV exercises
- Read CSV and Print NamesBeginner
- Predict the DictReader OutputBeginner
- Build a CSV StringIntermediate
- Fix the CSV Sum BugIntermediate
All Python exercises · 50 practice problems · File I/O & Data Formats quiz