Unit IV · Basics of Python Programming for Pharmaceutical Sciences (BP101T) · As per PCI B.Pharmacy Syllabus, NEP 2020
Every B.Pharmacy student who has worked with a spreadsheet full of patient records or pharmacokinetic readings knows the frustration of scrolling through hundreds of rows looking for a single value. Pandas is the Python library that solves exactly this problem. This post introduces what Pandas is, why it exists, and why it has become the standard tool for handling structured pharmaceutical data — from plasma concentration-time profiles to adverse drug reaction (ADR) logs — in both academic and industry settings.

What Is Pandas?
Pandas is a Python library purpose-built for working with structured, tabular datasets — data organized into rows and columns, much like a spreadsheet or a database table. The name itself comes from the econometrics term panel data, which describes multi-dimensional datasets built from repeated observations recorded over time — a description that fits pharmacokinetic (PK) sampling almost exactly, since a PK study records the same subject’s drug concentration at multiple time points after dosing.
The library was created by Wes McKinney in 2008 and has been released as free, open-source software ever since under the BSD license. Pandas is built on top of NumPy, the core numerical computing package in Python, and adds high-level structures and functions specifically designed for tabular, time-series, and mixed-type data — meaning a single table can hold numbers, text, and true/false values side by side without any trouble.
Why Pandas Matters in Pharmaceutical Sciences
Pandas shows up constantly across pharmacy practice and research because so much of what pharmacists and pharmaceutical scientists work with is naturally tabular. Some of the most common applications include:
- Pharmacokinetic (PK) studies — tracking how a drug’s concentration in plasma or another biological sample changes across a series of sampling time points after dosing.
- Pharmacovigilance — the ongoing collection, organization, and review of adverse drug reaction (ADR) reports submitted by patients, clinicians, or trial investigators.
- Clinical trial data management — handling and preparing participant records and study datasets before statistical analysis.
- Drug utilization studies — examining patterns in how medicines are actually prescribed and used in practice.
- Medication dispensing analysis — processing and summarizing dispensing and prescription records from a pharmacy or hospital system.
Because Pandas also connects smoothly with the rest of Python’s scientific ecosystem — NumPy for numerical arrays, SciPy for statistics, Matplotlib for plotting, and Scikit-learn for machine learning — it functions as the natural entry point into data analysis for a pharmacy student, and the skills built here carry directly into later units on data visualization and statistical interpretation.
Why Use Pandas Instead of a Spreadsheet?
Tools such as Microsoft Excel are perfectly adequate for small, simple datasets. The trouble starts when a project scales up — thousands of patient records, data pooled from multiple trial sites, or a long pharmacokinetic time-series with many subjects and many sampling points. At that scale, spreadsheets become slow, error-prone, and difficult to audit. A single mis-dragged formula or an accidentally sorted column can silently corrupt an entire dataset with no visible warning.
Pandas addresses these limitations through five core strengths:
| Capability | What It Means in Practice |
|---|---|
| Scalability | A DataFrame can hold millions of rows, limited only by available system memory — far beyond a typical spreadsheet’s comfortable range. |
| Reproducibility | Because every step is written as code, the same analysis can be re-run at any time and will always produce identical results. |
| Automation | Routine cleaning, transformation, and calculation steps can be scripted once and reused, cutting down on manual effort and human error. |
| Integration | Pandas connects directly with statistical and machine-learning tools like Statsmodels and Scikit-learn, and visualization libraries like Matplotlib and Seaborn. |
| Interoperability | Data can move freely in and out of Pandas from CSV, Excel, JSON, and SQL databases — the formats most clinical and laboratory systems actually export. |
Installing and Importing Pandas
Pandas is not part of Python’s built-in standard library, so it must be installed separately before it can be used. There are two common routes to getting it onto a system.
Method 1: Installing via a Python Distribution
Distributions such as Anaconda bundle Pandas together with many other scientific and analytical packages into one ready-to-use environment. This is a convenient option for students, since a single installer sets up Python, Pandas, NumPy, Matplotlib, and an IDE such as Spyder or Jupyter Notebook all at once.
Method 2: Installing via pip
Pandas can also be installed on its own using pip, Python’s standard package manager, directly from the command line or terminal:
# Install Pandas (run this in the command line / terminal)
pip install pandas
Importing Pandas Into a Script
Once installed, Pandas must be imported into every script or notebook that uses it. By convention, it is imported with the alias pd, which keeps code shorter and is instantly recognizable to anyone reading Pandas code. NumPy is very often imported alongside it, aliased as np, since the two libraries are frequently used together.
import pandas as pd
# NumPy is frequently used together with Pandas
import numpy as np
# Both Pandas and NumPy are now ready to use in the program
These two lines appear at the top of virtually every data-handling script a pharmacy student will write from this point in the syllabus onward — for reading PK datasets, cleaning ADR reports, or later plotting concentration-time curves.
as pd alias or write import Pandas with an incorrect capital P — Python is case-sensitive, and the actual package name is lowercase pandas.Frequently Asked Questions
Is Pandas part of core Python, or does it need to be installed separately?
Pandas is a third-party library, not part of Python’s standard library, so it must be installed separately using pip or obtained through a bundled distribution like Anaconda before it can be imported into a script.
Why is the alias “pd” used instead of writing “pandas” every time?
The alias is purely a convention adopted by the global Pandas community to keep code shorter and more readable. Technically any alias would work, but using anything other than pd would make code harder for others (including examiners and lab instructors) to follow at a glance.
Can Pandas handle Excel files as well as CSV files?
Yes. Pandas provides dedicated functions for reading and writing both formats, along with JSON and SQL databases. Reading CSV and Excel files in detail — including real PK study and ADR report datasets — is covered in the next topic of this unit.
Summary
Pandas is an open-source Python library, created by Wes McKinney in 2008, that provides fast and reliable tools for handling structured tabular data. It outperforms traditional spreadsheets on scalability, reproducibility, automation, integration, and interoperability, making it especially valuable for pharmacokinetic studies, pharmacovigilance, clinical trial data management, drug utilization studies, and dispensing analysis. It is installed via pip or a distribution like Anaconda, and conventionally imported with the alias pd. With this foundation in place, the next topics in this unit build up the two core Pandas data structures — the Series and the DataFrame — and then move into reading real pharmaceutical datasets from CSV and Excel files.
References
- Pharmacy Council of India (PCI) — B.Pharm Regulations, NEP 2020, BP101T Syllabus
- Python Software Foundation — Official Python Documentation, docs.python.org
- Pandas Development Team — Official Pandas Documentation, pandas.pydata.org
- Python Packaging Authority — pip documentation, pip.pypa.io
