Skip to content

Introduction to pandas in Python: Series, DataFrames and Installation

Pandas Series

pandas is an open-source Python library for analyzing and transforming labeled data. Its core structures are Series (one-dimensional) and DataFrame (two-dimensional). This beginner guide explains what each structure does, how to install pandas and how to avoid common setup errors.

What is pandas used for?

Common tasks include loading CSV and Excel files, selecting rows and columns, handling missing values, joining tables, grouping records, reshaping data and analyzing dates. pandas is an in-memory analysis library, not a database or distributed engine; datasets larger than available memory may need chunking or another tool.

Series: one-dimensional labeled data

A Series contains values associated with an index. The index can be integers, strings, dates or other supported labels.

Illustration of a pandas Series with labeled index and values
import pandas as pd
scores = pd.Series([90, 85], index=["Asha", "Ravi"])
print(scores.loc["Asha"])  # 90

DataFrame: two-dimensional labeled table

A DataFrame has rows and named columns. Different columns can have different data types, and each row has an index label.

Illustration of a pandas DataFrame with row and column labels
DataFrame example: labeled rows and columns
df = pd.DataFrame({"name": ["Asha", "Ravi"], "score": [90, 85]})
print(df.shape)          # (2, 2)
print(df["score"].mean()) # 87.5
Introduction to pandas

Install pandas with pip

Create or activate the Python environment you intend to use. In a terminal, install pandas into that environment with the interpreter-specific command below. A virtual environment is recommended to avoid conflicting dependencies.

python -m pip install pandas
# On some Windows systems, use: py -m pip install pandas

For Excel .xlsx files, install an appropriate optional engine such as openpyxl: python -m pip install openpyxl. Run installation commands in a terminal, not inside the Python interpreter.

Install pandas with conda or Anaconda

If you use conda, activate your intended environment and run conda install pandas. Miniconda is a smaller starting installation; Anaconda includes a broader package collection. Availability and licensing terms for Anaconda distributions can vary by organization: consult Anaconda’s current terms before organizational deployment. See our Anaconda installation guide.

Verify the installation

import pandas as pd
print(pd.__version__)
print(pd.DataFrame({"a": [1, 2]}))

The conventional alias pd is simply a shorter name for the imported module. If you see ModuleNotFoundError, check that the terminal running pip or conda and your notebook or IDE use the same Python environment.

Load and inspect data

import pandas as pd
df = pd.read_csv("people.csv")  # File must exist at this path
print(df.head())
print(df.dtypes)
print(df.isna().sum())
# For Excel: df = pd.read_excel("people.xlsx")

Use df.loc[] for label-based selection and df.iloc[] for integer-position selection. A DataFrame can have missing values; verify column types and missing-data counts before drawing conclusions. Learn more in our DataFrame creation tutorial.

Troubleshooting and safety

FileNotFoundError: verify the file path and current working directory. ImportError for Excel: install the required reader engine in the active environment. Slow or out-of-memory operations: load fewer columns, process files in chunks or use a scalable tool. Avoid loading untrusted pickle files: deserializing pickle data can execute code.

Frequently asked questions

Is pandas the same as NumPy? No. pandas builds on NumPy and other components to offer labeled data structures. Is pandas free? pandas itself is open-source; separate distributions and services may have their own terms. Can pandas read Excel? Yes, with an appropriate installed engine. Can pandas replace SQL? It can perform many tabular operations, but is not a persistent database.

Reference: official pandas getting-started documentation and installation guidance.

Leave a Reply

Your email address will not be published. Required fields are marked *