Read CSV and Print Names
Beginner · 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 the CSV data below (already stored in csv_data), use csv.reader to read it and print only the name column from each data row (skip the header).
The data:
name,age
Alice,30
Bob,25
Charlie,35Expected output:
Alice
Bob
Charlieimport csv
import io
csv_data = 'name,age\nAlice,30\nBob,25\nCharlie,35'
f = io.StringIO(csv_data)
# Your code here
More CSV exercises
- Predict the DictReader OutputBeginner
- Build a CSV StringIntermediate
- Fix the CSV Sum BugIntermediate
- Filter and Count CSV RowsAdvanced
All Python exercises · 50 practice problems · File I/O & Data Formats quiz