Pandas Read CSV

Load data from CSV text or files.

✍️ 3 exercises + code challenge in this lesson

pd.read_csv("file.csv") loads a CSV file into a DataFrame. It also reads from URLs and text buffers.

Save a DataFrame with df.to_csv("out.csv", index=False). Pandas also reads Excel (read_excel), JSON (read_json) and SQL databases.

Key Takeaways: Pandas Read CSV

Mastering Pandas Read CSV helps you write clean and reliable Pandas code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Pandas Read CSV Code Example

Pandas
import pandas as pd
from io import StringIO

csv = """name,department,salary
Ali,IT,120000
Sara,HR,95000
Usman,IT,110000
Hina,Sales,88000"""

df = pd.read_csv(StringIO(csv))
print(df)
print(len(df), "employees")
Output
name department  salary
0    Ali         IT  120000
1   Sara         HR   95000
2  Usman         IT  110000
3   Hina      Sales   88000
4 employees
Free sign-in required · Google login available

Pandas Read CSV Practice Exercises

Check what you learned in “Pandas Read CSV”.

/ 3 solved
Fill in the blank

Load a CSV file.

df = pd.("data.csv")
✓ Correct! Not quite. Try again.
Multiple choice

Which method saves a DataFrame to CSV?

✓ Correct! Not quite. Try again.
Code challenge

Read the CSV text and print the total of the "amount" column.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services