Course contentsShow
← Data Science
Lesson 1126 of 2,14529. Data Wrangling WorkflowsFree lesson

Reading CSV with Pandas: Basic Options

Master pd.read_csv() with key parameters: delimiter, header, names, skiprows, and usecols.

Reading CSV with Pandas: Basic Options

What you'll learn: How to customize pd.read_csv() with essential parameters to handle real-world CSV quirks and structure.

Why Basic Options Matter

You've already seen that CSV files come with structure variations and common issues. Pandas' read_csv() function offers powerful parameters to handle these gracefully. Think of these options as adjusting the "lens" through which Pandas interprets your file—you're telling it exactly how to parse what it sees.

Core Parameters You Need to Know

delimiter (or sep): Specifies the character separating values. While commas are default, you might encounter tabs ('\t'), pipes ('|'), or semicolons (;).

df = pd.read_csv('data.csv', delimiter='|')

header: Tells Pandas which row contains column names. Use header=0 (default) for the first row, header=None if there are no headers, or header=2 to skip introductory rows.

df = pd.read_csv('data.csv', header=None)  # No header row

names: Lets you assign custom column names, especially useful when header=None.

df = pd.read_csv('data.csv', header=None, names=['ID', 'Name', 'Score'])

skiprows: Skips specified rows at the file's start—ideal for metadata or comments. Pass an integer to skip that many rows, or a list for specific rows.

df = pd.read_csv('data.csv', skiprows=3)  # Skip first 3 rows

usecols: Reads only specified columns, saving memory and processing time. Pass column names or indices.

df = pd.read_csv('data.csv', usecols=['Name', 'Score'])

Combining Options for Real Scenarios

These parameters work together. For a pipe-delimited file with 2 metadata rows and only needing specific columns:

df = pd.read_csv('messy_data.csv', delimiter='|', skiprows=2, usecols=['ID', 'Value'])

Key Takeaway: Mastering delimiter, header, names, skiprows, and usecols lets you cleanly import almost any CSV file by precisely controlling how Pandas interprets its structure.