Data Scientist · Step 2 of 8 · 12 min
Python and notebooks for data
Load a dataset into pandas in a free notebook and filter, group and join it.
Notebooks: code, results and notes together
A notebook is a document made of cells. Some cells hold Python code, which you run one at a time, and the result appears right below. Other cells hold plain notes. Jupyter is the standard format. Google Colab and Kaggle notebooks let you use it free in the browser, with nothing to install.
Notebooks are perfect for exploring. You try something, look at the output, and adjust. That speed is why almost every data scientist uses them.
pandas and the DataFrame
pandas is the Python library for tables. Its main object is the DataFrame: rows and named columns, like a spreadsheet you control with code. You usually start with import pandas as pd, then df = pd.read_csv('sales.csv'). Now df.head() shows the first rows, df.shape tells you rows and columns, and df.info() lists each column and its type.
If you know spreadsheets, you already know the ideas. pandas just lets you repeat them exactly, on millions of rows.
Four moves you will use every day
Filter: df[df['country'] == 'Vietnam'] keeps only matching rows. Select: df[['date', 'amount']] keeps only those columns. Group: df.groupby('city')['amount'].sum() gives a total per city, like a pivot table. Join: pd.merge(orders, customers, on='customer_id') matches rows from two tables, like a lookup.
After a merge, always check the row count. If it jumped unexpectedly, the key was not unique and some rows were duplicated. That one habit catches a lot of silent mistakes.
Make it reproducible
A notebook is reproducible when someone else can run it top to bottom and get the same result. Because cells can be run in any order, it is easy to end up with a notebook that only works on your screen. Before you share, use “Restart and run all” and fix whatever breaks.
Keep the raw data untouched and do all cleaning in code. Write a short note above each step saying why. Future you is the person most grateful for this.
Try it
Your first DataFrame in Google Colab
- 1.Open colab.research.google.com and create a new notebook.
- 2.Run: import pandas as pd, then df = pd.read_csv('sample_data/california_housing_train.csv'). Colab ships this file in every new notebook.
- 3.Run df.head(), df.shape and df.describe() and read what each tells you.
- 4.Try one filter and one groupby. If stuck, paste your code and error into a chatbot with the prompt below.
I am learning pandas. Here is my code: [CODE]. Here is the error or output: [OUTPUT]. Explain what went wrong in plain words, show the fixed code, and do not add anything I did not ask for.