What Is Pandas?
Pandas is an open-source Python library, built on top of NumPy, designed for working with structured and labeled data — the kind you would normally find in a spreadsheet, a SQL table, or a CSV file. Where a raw NumPy array is a grid of homogeneous numbers indexed only by integer position, pandas introduces two labeled data structures, Series and DataFrame, that carry row and column labels alongside the data itself, along with heterogeneous column types (numbers, strings, dates, categories) in a single table. This labeling is what makes pandas the workhorse of real-world data analysis: you can select 'the revenue column for March 2026' by name instead of remembering which integer index it happens to occupy, and pandas will automatically align data by label when you combine multiple datasets.
Cricket analogy: Pandas is like a scorecard that lets you select 'Kohli's strike rate in the third over' by name instead of remembering which row number it sits on, and it aligns two scorecards by player name automatically when merging them.
Why Pandas Exists Alongside NumPy
NumPy is optimized for fast numerical computation on homogeneous n-dimensional arrays, but most real datasets are messier: they mix strings, numbers, missing values, and dates, and they need to be joined, grouped, filtered, and reshaped based on meaningful labels rather than raw array positions. Pandas fills that gap by wrapping NumPy arrays (one per column, historically referred to as 'blocks') with an index, column names, and a rich API of relational-style operations — merges, joins, group-by aggregations, pivot tables — that mirror what you would do in SQL or Excel, but programmatically and reproducibly. Under the hood pandas still leans on NumPy's vectorized operations for performance, so understanding NumPy fundamentals (dtypes, broadcasting, vectorization) directly improves how you write efficient pandas code.
Cricket analogy: NumPy handles fast numerical crunching of raw ball-by-ball speeds, but real match data mixes venue names, weather notes, and dates, so pandas wraps that NumPy data with labels to support merges like combining batting and bowling scorecards.
The Two Core Data Structures
A Series is a one-dimensional labeled array — think of it as a single column with an index attached. A DataFrame is a two-dimensional labeled table made up of multiple Series that share the same index, each column potentially holding a different dtype (integers, floats, strings, datetimes, booleans, or categoricals). Every DataFrame column, when selected on its own (e.g. df['price']), returns a Series, which is why fluency with Series operations transfers directly to working with individual DataFrame columns.
Cricket analogy: A Series is like a single column of a scorecard - just the run tally with player names attached - while a DataFrame is the full scorecard combining batting, bowling, and fielding columns that all share the same player index.
import pandas as pd
data = {
'product': ['Widget', 'Gadget', 'Gizmo'],
'price': [19.99, 34.50, 12.75],
'in_stock': [True, False, True],
}
df = pd.DataFrame(data)
print(df)
# product price in_stock
# 0 Widget 19.99 True
# 1 Gadget 34.50 False
# 2 Gizmo 12.75 True
print(type(df['price'])) # <class 'pandas.core.series.Series'>
print(df.dtypes)
# product object
# price float64
# in_stock bool
# dtype: object
Pandas takes its name from 'panel data', an econometrics term for datasets that combine cross-sectional and time-series observations — reflecting its original purpose of making financial and economic data analysis in Python practical.
What Pandas Is Commonly Used For
In practice, pandas is the glue between raw data sources (CSV files, databases, APIs, Excel workbooks) and downstream analysis or machine learning: reading and cleaning data, handling missing values, converting types, filtering rows with boolean conditions, grouping and aggregating, reshaping between wide and long formats, and exporting results. Its tight integration with NumPy means numeric columns can be fed directly into libraries like scikit-learn or PyTorch once cleaned, making pandas the de facto first stage of nearly every Python data pipeline.
Cricket analogy: Pandas is the glue between raw scoresheets, ball-tracking feeds, and video logs and downstream analytics, cleaning missing overs, filtering by team, and aggregating a bowler's stats before feeding numbers into a performance model.
A common beginner misconception is that pandas DataFrames are just 'Excel in Python'. They are much more powerful for reproducibility and scale — but unlike a spreadsheet, most operations return new objects rather than modifying data in place by default, which affects how you should write pandas code (assign results rather than assuming mutation).
- Pandas builds on NumPy to add labeled, heterogeneous, tabular data structures: Series and DataFrame.
- A Series is a 1-D labeled array; a DataFrame is a 2-D table of columns, each a Series, sharing an index.
- Pandas automatically aligns data by label, not by raw position, when combining datasets.
- Most pandas operations return new objects rather than mutating in place unless you explicitly reassign or use
inplace=True. - Pandas is the standard bridge between messy real-world data sources and clean numeric arrays used by ML/analysis libraries.
- DataFrame columns can each hold a different dtype, unlike a raw NumPy array which is homogeneous.
Practice what you learned
1. What is the fundamental difference between a NumPy array and a pandas DataFrame?
2. What type of object do you get when you select a single column from a DataFrame, e.g. `df['price']`?
3. By default, when you call a method like `df.dropna()` without `inplace=True`, what happens?
4. What does it mean that pandas 'aligns data by label'?
5. Which library does pandas build directly on top of for its underlying array storage and vectorized computation?
Was this page helpful?
You May Also Like
Series Basics
Learn the anatomy of a pandas Series — its values, index, and name — and how label-based alignment, vectorized operations, and dtype inference make it more than a plain list.
DataFrame Basics
Understand the structure of a pandas DataFrame — rows, columns, index, and dtypes — and the core operations for creating, inspecting, and selecting from tabular data.
What Is NumPy?
NumPy is Python's foundational library for fast, memory-efficient numerical computing, built around a homogeneous multi-dimensional array type called ndarray.
Reading and Writing Data
Learn pandas' file I/O functions — read_csv, read_excel, read_json, to_csv, and to_parquet — plus the key parameters that control parsing, dtypes, and output format.