0PricingLogin
Pandas & NumPy Academy · Lesson

Reading CSV Files

Load CSV files with pd.read_csv, control delimiters, header rows, and index columns, and preview the result.

Why CSV Is the Universal Format

CSV (Comma-Separated Values) is the most widely used format for exchanging tabular data. It is human-readable, supported by every database, spreadsheet, and analytics tool, and requires no schema definition. pd.read_csv() is the most frequently called Pandas function in data analysis because virtually every public dataset, API export, or database dump is available in CSV.

import pandas as pd

# Read a CSV file from disk
df = pd.read_csv('data/sales.csv')
print(df.shape)
print(df.head())

Basic read_csv() Call

The only required argument is the file path (string or Path object). By default Pandas assumes the first row is the header (column names), the delimiter is a comma, and values are inferred to appropriate dtypes. The resulting DataFrame has a default integer RangeIndex. Always call df.info() immediately after loading to spot type inference issues.

import pandas as pd

df = pd.read_csv('products.csv')

# Equivalent with explicit defaults:
df = pd.read_csv('products.csv',
                 sep=',',
                 header=0,
                 index_col=None)

All lessons in this course

  1. Reading CSV Files
  2. Reading Excel and JSON Files
  3. Writing DataFrames to Files
  4. Reading from URLs and StringIO
← Back to Pandas & NumPy Academy