logo

Reading CSV Files with Pandas

Most real-world data comes from files, not manual entry. CSV (comma-separated values) is the most common format, and pandas reads it with one line.

import pandas as pd

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

That's it. Pandas automatically detects headers, infers data types, and creates your DataFrame.

For files with different separators (like tabs), specify the delimiter:

df = pd.read_csv('data.tsv', sep='\t')

You can also read directly from URLs - no download needed:

url = 'https://example.com/data.csv'
df = pd.read_csv(url)

I demonstrate reading from various sources including Excel, JSON, and databases in my Pandas course.