In this lesson you will
- Build and inspect a DataFrame and add calculated columns
- Filter and sort rows with conditions
- Read CSV data, handle missing values and summarise with groupby
DataFrames, columns and calculated columns
A DataFrame is built here from a dictionary: each key becomes a column name and each list becomes the column values, all of the same length. shape gave (6, 4), six rows and four columns, and head(3) showed the first three rows with the index on the left, the row labels 0, 1, 2 that pandas adds. dtypes lists each column type: whole numbers are int64, and in pandas 3 text columns use the new str type. Always look at shape, head() and dtypes first when you load new data; they catch most surprises early.
The key idea in pandas is working on whole columns at once. sales["qty"] * sales["price"] multiplies every row by its own price with no loop, and assigning it to sales["total"] adds a new column. Double brackets, sales[["city", "total"]], pick several columns and return a smaller table. Column methods summarise: the six totals added up to 2040 and the average quantity was 5.0. This style, called vectorised, is also much faster than a Python loop on large tables, because the work happens in compiled NumPy code.
Console
- Console messages, errors, form data and clicked links appear here.
After loading numpy and pandas, this printed (6, 4), the first three rows, the types str for city and product and int64 for qty and price, the six city totals from 360 to 600, then 2040 5.0 and the version 3.0.2.
Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 2 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
How do I install pandas on my computer?
Run pip install pandas in a terminal, ideally inside a virtual environment made with python -m venv .venv. It installs NumPy too. Then import pandas as pd works in any script or notebook.
Can pandas read Excel files?
Yes, with pd.read_excel("file.xlsx"), which needs the openpyxl package installed. df.to_excel() writes one back. CSV is simpler and faster when you only need the data.
What is the difference between loc and iloc?
loc selects by labels, the index values and column names. iloc selects by position, counting from 0. After sorting or filtering the labels no longer match positions, so the two can give different rows.
How much data can pandas handle?
Comfortably anything that fits in memory a few times over, often millions of rows on a laptop. In the browser the limit is lower. For data larger than memory, tools such as DuckDB or Polars are worth learning next.
How do I draw a chart from a DataFrame?
With matplotlib installed, by_city.plot(kind="bar") draws a bar chart in one line. Jupyter notebooks show it inline; in a script, call matplotlib.pyplot.show() or save it with savefig().
Sources
Facts in this lesson were checked against these official pages on 4 December 2026.
- pandas: 10 minutes to pandas
- pandas: Group by (split-apply-combine)
- pandas: Working with missing data
- pandas: read_csv
- Pyodide: Loading packages
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.