Read rows with csv.reader

import csv

with open("data.csv", newline="") as f:
    reader = csv.reader(f)
    for row in reader:
        print(row)

Each row is a list of strings. Passing newline="" is recommended so the module handles line endings correctly across platforms.

Read rows as dictionaries with DictReader

import csv

with open("data.csv", newline="") as f:
    reader = csv.DictReader(f)
    for row in reader:
        print(row["name"], row["age"])

DictReader reads the first line as the header and turns every following row into a dictionary, so you access values by column name instead of a numeric index.

Read a CSV into a pandas DataFrame

import pandas as pd

df = pd.read_csv("data.csv")
print(df.head())

If you already use pandas for analysis, read_csv loads the whole file into a table in one line.

Which method should you use?

  • csv.reader — lightweight, no dependencies, good when you only need the raw rows.
  • csv.DictReader — best when the file has headers and you want readable column access.
  • pandas — ideal for analysis, filtering, and large tabular data.
  • Common mistake: forgetting newline="", which can produce blank rows on Windows.

Frequently asked questions

How do I read a CSV that uses a semicolon separator?

Pass the delimiter explicitly: csv.reader(f, delimiter=";"), or in pandas use pd.read_csv("data.csv", sep=";").

How do I skip the header row?

Call next(reader) once before your loop to consume the first line, or simply use DictReader, which treats the header separately.

Want to get confident with files and the standard library? Try our free Python course.