Your notebook is a kitchen. Data is your ingredients. Learn how to bring them in — and ship the finished dish out.
The big idea
Your notebook doesn't hold data — it just works with it
Think of your notebook like a chef
A chef doesn't grow the vegetables or bottle the olive oil. They bring ingredients in from outside, cook them, and send the meal out. Your Jupyter notebook works the same way. It doesn't store data — it just borrows it, does something with it, then sends the results somewhere.
CSV, Excel, database...
clean, analyze, transform
CSV, Excel, JSON...
Bring data in
Load a file so Python can read and work with it.
Send data out
Save your cleaned or processed data to a new file.
Importing data
Four ways to bring data into your notebook
First: always import pandas
Almost every import method uses pandas — the go-to Python library for working with data. Think of it as the knife every chef needs before they start cooking.
as pd part is a shortcut — instead of typing pandas every time, you write pd. Everyone does this. It's a universal convention.Pick your import method
Click each tab to see the code and when to use it.
A CSV is a plain text file where values are separated by commas. It's the most common data format — like a spreadsheet saved as plain text.
.head() shows just the first 5 rows — great for peeking at your data without printing thousands of rows at once.Excel files (.xlsx) are common in offices and schools. Pandas can read them directly — no need to convert to CSV first.
openpyxl first. Run this in a cell:!pip install openpyxlIf data lives on a website (like a government open data portal), you can load it directly from its URL — no downloading needed.
Databases store large amounts of structured data. You connect to one and use SQL to fetch exactly the rows you need.
Exporting data
Save your work so you can share it or use it elsewhere
Why export?
After cleaning or analyzing data in your notebook, you'll want to save the results. Maybe you're sending it to a colleague, uploading it to a website, or feeding it into another tool. Exporting lets you do that.
Imagine you cleaned up a messy dataset
You removed blank rows, fixed typos, and added a "grade" column. Now you want to save that clean version — not just see it inside the notebook.
Choose your export format
CSV is the safest format — almost every tool on earth can open it. Use this when in doubt.
index=False stops pandas from adding an ugly extra column of row numbers to your file. Almost always include it.Great for sharing with people who prefer spreadsheets — keeps formatting, supports multiple sheets, etc.
JSON is a format used by websites and apps. Use this when you're feeding data into a web application or API.
Universal. Use for everything.
For humans who use Excel.
For apps and websites.
Exporting the notebook itself
Share your whole analysis — code, results, and all
Data vs notebook — what's the difference?
So far we've exported data (just the numbers and columns in a file). But sometimes you want to share the whole notebook — the code, the charts, the explanations, and the outputs together.
How to export
In Jupyter: click File → Download as → pick your format.
For reports and presentations. Looks professional.
A webpage. Anyone can open it in a browser.
Just the code, no outputs. For developers.
The raw notebook file — for other Jupyter users.
Real-life example
You've analyzed your class's test scores in a notebook. Your teacher wants to see the work. You export as HTML — she opens it in Chrome and sees everything: the code, the table, the chart. No Python needed on her end.
Quick quiz
Let's see what stuck
Post a Comment