CSV Files (Pandas)
π¨π Technique Card: Reading CSV Files with Pandas (practical)
Skill: Reading and exploring data
Youβll need: Python, Pandas installed (pip install pandas
), a .csv
file
Youβre learning this because: It helps you work with real-world data easily, especially for Digital Changemaker projects.
π What Youβll Learn
- How to import
pandas
- How to read a CSV file into a DataFrame
- How to look at the first few rows
- How to understand the shape and structure of your data
π§° Step-by-Step
- Import pandas
import pandas as pd
- Read a CSV file
Replace"data.csv"
with your own file name.
data = pd.read_csv("data.csv")
- Look at the top of the data
This shows the first 5 rows.
print(data.head())
- See how many rows and columns there are
print(data.shape)
- See the column names
print(data.columns)
- See a summary of the data
Useful to check numbers and missing values.
print(data.info())
π‘ Tip
- Make sure your
.csv
file is in the same folder as your Python file, or give the full path. - If you get encoding errors, try:
pd.read_csv("data.csv", encoding="utf-8")
π― Try It Out
Load an example CSV file - create one like the following if you want to keep it simple:
Name,Food,Distance_km
Tom,Apples,150
Sara,Strawberries,600
Ben,Carrots,50
Use the tools given on this technique card to explore the data.
π§ͺ Make It Your Own
- Use Pandas to work with data from our digital changemakers project idea cards!