Read and inspect a CSV

3.1.1

Preserve identifiers, control missing-value parsing, and inspect the schema before analysis.

On this page

Choose CSV parsing rules

read_csv accepts a path or a file-like object. Use dtype for identifiers with leading zeros. Set na_values for known missing codes. When keep_default_na=False is used without na_values, pandas does not use its default missing-string list.

from io import StringIO
import pandas as pd

source = StringIO("id,item,total\n001,Tea,3\n002,Cake,ERROR\n")
frame = pd.read_csv(source, dtype={"id": "string"}, na_values={"total": ["ERROR"]})
print(frame["id"].tolist())
print(frame["total"].isna().sum())
Example output
['001', '002']
1

Inspect shape and types

Use head() for examples, shape for counts, and dtypes for inferred types. DataFrame.info() prints a summary including column types. Check delimiters, encoding, parsing errors, and missing values when the output differs from the source schema.

Official references