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.
Load data from CSV text or files.
✍️ 3 exercises + code challenge in this lessonpd.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.
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.
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")
name department salary 0 Ali IT 120000 1 Sara HR 95000 2 Usman IT 110000 3 Hina Sales 88000 4 employees
Check what you learned in “Pandas Read CSV”.
Load a CSV file.
df = pd.("data.csv")
Which method saves a DataFrame to CSV?
Read the CSV text and print the total of the "amount" column.
Free sign-in required · Google login available
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