CSV stands for Comma-Separated Values. It's a common file format used to store tabular data, like spreadsheets or databases.
Example of a CSV file content:
name,age,city
Alice,30,New York
Bob,25,London
Reading a CSV File Using Python
Python’s built-in csv
module lets you easily read CSV files.
Here’s how to read a CSV and print its rows:
import csv
with open("people.csv", "r") as file:
reader = csv.reader(file)
for row in reader:
print(row)
Working with Headers
Often, CSVs include a header row. You might want to skip it:
next(reader)
# skips the first row (header)
CSV is one of the most common data formats used in analytics. Knowing how to load and read it is foundational for working with real-world data.