How to read a CSV file with pandas
October 28, 2026 · 1 min read
Use pd.read_csv("file.csv"). It reads the file and returns a DataFrame, with column names taken from the first line.
Load a CSV and look at it
Save this as people.csv:
name,city,age,score
Ada,London,36,91.5
Ben,Paris,29,78.0
Cara,Berlin,41,85.25
Dev,Delhi,33,88.0
Then, in a script in the same folder:
import pandas as pd
df = pd.read_csv("people.csv")
print(df.head(2))
print(df.shape)
df.info()
print(pd.read_csv("people.csv", usecols=["name", "score"]))
Output:
Output
name city age score 0 Ada London 36 91.5 1 Ben Paris 29 78.0 (4, 4) <class 'pandas.DataFrame'> RangeIndex: 4 entries, 0 to 3 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 name 4 non-null str 1 city 4 non-null str 2 age 4 non-null int64 3 score 4 non-null float64 dtypes: float64(1), int64(1), str(2) memory usage: 295.0 bytes name score 0 Ada 91.50 1 Ben 78.00 2 Cara 85.25 3 Dev 88.00
What each line does
head(2)shows the first two rows. With no number, it shows five.shapeis(rows, columns), so(4, 4)means four rows and four columns.info()lists each column's type and how many values are not missing. It prints by itself, so you don't wrap it inprint(). The memory figure may differ on your computer.usecols=loads only the columns you list. It's handy for wide files.
Check the types every time. Here age is int64 and score is float64, because pandas works them out from the values.
Common mistake
FileNotFoundError. The path is relative to the folder you run Python from, not the folder the script is in. If the file is in data/, write pd.read_csv("data/people.csv").
Wrong separator. If everything lands in one column, the file probably uses semicolons. Add sep=";".
Call pd.read_csv(path), then check head(), shape and info() before you do anything else with the data.