April 27, 2026

Pandas Series & DataFrame (with patient & PK datasets)

Pandas Series & DataFrame Explained for Pharmacy Students (Patient Datasets & PK Tables)

Pandas provides two powerful data structures: Series and DataFrame. These are widely used in pharmaceutical sciences for handling patient datasets, pharmacokinetic (PK) tables, and ADR reports.


๐Ÿ”ท What is a Pandas Series?

A Series is a one-dimensional labeled array (similar to a single column in a table).

import pandas as pd

dose = pd.Series([500, 650, 400])
print(dose)
๐Ÿ’ก Key Insight: Series = Single column of data.

๐Ÿ’Š Pharma Example (Dose Data)

doses = pd.Series([500, 650, 700], index=["P1", "P2", "P3"])
print(doses)

๐Ÿ”ท What is a DataFrame?

A DataFrame is a two-dimensional table consisting of rows and columns.

data = {
    "Patient": ["P1", "P2"],
    "Dose": [500, 650]
}

df = pd.DataFrame(data)
print(df)

๐Ÿ’Š Pharmacokinetic (PK) Table Example

data = {
    "Time": [0, 1, 2, 3],
    "Concentration": [0, 5.2, 4.1, 2.8]
}

pk_df = pd.DataFrame(data)
print(pk_df)

Used to analyze drug concentration over time.


๐Ÿ”ท Accessing Data in DataFrame

๐Ÿ“˜ Column Access

print(df["Dose"])

๐Ÿ“˜ Row Access

print(df.iloc[0])

๐Ÿ”ท Basic Operations

๐Ÿ“˜ Mean Dose

print(df["Dose"].mean())

๐Ÿ“˜ Maximum Dose

print(df["Dose"].max())

๐Ÿ”ท Series vs DataFrame

FeatureSeriesDataFrame
Dimension1D2D
StructureSingle columnTable
UseSingle variableFull dataset

๐Ÿง  Memory Tricks

  • Series โ†’ Single column
  • DataFrame โ†’ Table
  • iloc โ†’ Row access

๐Ÿงช Practice Exercise

Create a DataFrame and:

  • Store patient names
  • Store doses
  • Calculate average dose

๐Ÿงช Mini Project

Create PK dataset:

import pandas as pd

data = {
    "Time": [0, 1, 2, 3],
    "Conc": [0, 5, 4, 3]
}

df = pd.DataFrame(data)

print("Average Conc:", df["Conc"].mean())

๐Ÿ“ MCQs

  1. Series is:
    a) 2D
    b) 1D
    c) 3D
    d) None
    Answer: b

  2. DataFrame is:
    a) List
    b) Table
    c) String
    d) Loop
    Answer: b

  3. iloc is used for:
    a) Column access
    b) Row access
    c) File read
    d) Calculation
    Answer: b

โ“ FAQs

Where is DataFrame used in pharmacy?

In patient datasets, PK studies, and ADR analysis.

What is difference between Series and DataFrame?

Series is 1D, DataFrame is 2D table.


๐Ÿ“ฅ Download PK Dataset Practice Files

Practice real pharmacokinetic data analysis.


โžก Next Topic: Reading CSV & Excel Files using Pandas โ†’

Recommended readings

  1. Introduction to Pandas (Why it is used in Pharma Data Analysis)
  2. Pandas Series & DataFrame (with patient & PK datasets)
  3. Reading CSV & Excel Files (PK datasets, ADR reports)
  4. Inspecting Data (head(), tail(), info(), describe())
  5. Data Cleaning & Missing Values (real clinical dataset problems)
  6. Filtering & Selecting Data (high dose, ADR filtering)
  7. Grouping & Aggregation (mean dose, ADR frequency)

Question Bank Unit 4: Data Handling with Pandas

For detailed information: Basics of Python Programming for Pharmaceutical Sciences