Pandas Introduction
last modified November 17, 2026 Python 3.15
Pandas is a Python library for working with data that is arranged in tables or in sequences, much like a spreadsheet or a database table. It is the standard tool in Python for data analysis, the process of inspecting, cleaning and summarising data in order to draw conclusions from it.
This tutorial gets you started. We install the library, look at the customary import, write a first small program, and meet the two structures that everything in pandas is built on.
What is pandas?
The name pandas comes from panel data, a term used for data collected over time from many subjects. The library gives us convenient objects for holding data, along with methods for selecting rows, filtering values, grouping, joining tables and reading files. Instead of writing loops over Python lists, we express operations on whole columns at once.
Typical uses include loading CSV or Excel files, cleaning missing values, computing statistics, reshaping data and preparing it for plotting or machine learning. The examples in this article were checked with pandas 3.1.1.
Installation
Pandas is installed from the command line with the pip package installer, a program that downloads and installs Python libraries:
pip install pandas
If you use a virtual environment, activate it first so the library is installed into that environment. Once installed, the interpreter can import it.
The pd import convention
Almost every pandas program begins with the line import pandas as pd.
The as pd part gives the library a short alias, so we write
pd.DataFrame instead of pandas.DataFrame. This is a
convention rather than a rule, but following it makes pandas code recognizable
to other programmers.
A first program
The following program builds both core objects: a Series from a plain Python list, and a DataFrame from a dictionary whose keys become column names. We print them one after the other, with a blank line between.
import pandas as pd
s = pd.Series([10, 20, 30, 40])
df = pd.DataFrame({'name': ['Alice', 'Bob', 'Cindy'], 'age': [25, 32, 28]})
print(s)
print()
print(df)
The Series is printed as a column of values with an index on the left: the numbers 0 to 3 were supplied automatically. The DataFrame is printed as a table with a header row. Each row still has an index, and the two columns hold the names and ages we provided.
$ python intro_first.py
0 10
1 20
2 30
3 40
dtype: int64
name age
0 Alice 25
1 Bob 32
2 Cindy 28
Series and DataFrame in a nutshell
A Series is a one-dimensional object: a single column of values together with an index that labels each entry. A DataFrame is a two-dimensional object: a collection of Series that share the same index, forming a table with rows and columns. You can think of a DataFrame as a dictionary of columns, or as a spreadsheet sheet.
Almost every operation in pandas works on one or both of these objects. The Series is covered in detail in the Pandas Series tutorial, and the DataFrame in the Pandas DataFrame tutorial.
Why labelled data helps
The index is not just row numbering; it is a set of labels, human readable names attached to the data. Here we give the days of the week as labels and then fetch one value by its label rather than by its position.
import pandas as pd temps = pd.Series([22, 24, 19], index=['Mon', 'Tue', 'Wed']) print(temps) print() print(temps['Tue'])
Writing temps['Tue'] asks for the temperature labelled Tue and
returns 24. With a plain Python list we would have to remember that Tuesday is
at position 1; labels let us state what we mean directly, and the answer stays
correct even if rows are reordered.
$ python intro_labels.py Mon 22 Tue 24 Wed 19 dtype: int64 24
Source
Pandas Table oriented data Documentation, Pandas Series Documentation, and Pandas DataFrame Documentation
In this article we have installed pandas, adopted the pd import,
created a first Series and DataFrame, and seen how index labels make data easier
to refer to. Continue with the Series tutorial and
the DataFrame tutorial for a closer look at
both structures.
Author
List all Pandas tutorials.