Introduction to Pandas
Ever wondered how to efficiently manage and analyse data in Python? Meet Pandas — your go-to library for powerful, intuitive data handling. If NumPy gave us fast numbers, Pandas gives us labelled, spreadsheet-like data.
1What is Pandas?
- 🐼 It's Python's go-to library for data analysis.
- ⚡ It offers high performance and intuitive data structures.
- 📦 The name "Pandas" comes from "Panel Data" — a term for multi-dimensional datasets.
- 👨💻 It was created by the brilliant Wes McKinney in 2008.
2Installing & importing Pandas
Pandas isn't built into Python, so first you install it once with pip (Python's package installer). Open a terminal or command prompt and run:
pip install pandasThen, in every program, you import it. The whole world imports it under the short alias pd:
import pandas as pd3The three data structures
Pandas organises your data into specialised data structures. There are three in the family — but only the first two matter for you:
Tap a structure to see how its shape changes.
A single labelled column — like one column of a spreadsheet, or a Python list with superpowers. This whole chapter is about the Series.
4Series vs DataFrame: the quick gist
Both hold data, but they differ in shape and in the rules they follow:
| Property | Series (1-D) | DataFrame (2-D) |
|---|---|---|
| Dimensions | 1-dimensional | 2-dimensional |
| Type of data | Homogeneous (all one type) | Heterogeneous (columns can differ) |
| Mutability | Values mutable · size immutable | Values mutable · size mutable |
Simply put: a Series is for single lists, and a DataFrame is for tables. This chapter now zooms right into the Series — the building block that everything else is made of.
Where does the name 'Pandas' come from?
Which data structure is 1-dimensional and holds all one type of data?