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)
๐ 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
| Feature | Series | DataFrame |
|---|---|---|
| Dimension | 1D | 2D |
| Structure | Single column | Table |
| Use | Single variable | Full 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
- Series is:
a) 2D
b) 1D
c) 3D
d) None
Answer: b - DataFrame is:
a) List
b) Table
c) String
d) Loop
Answer: b - 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
- Introduction to Pandas (Why it is used in Pharma Data Analysis)
- Pandas Series & DataFrame (with patient & PK datasets)
- Reading CSV & Excel Files (PK datasets, ADR reports)
- Inspecting Data (head(), tail(), info(), describe())
- Data Cleaning & Missing Values (real clinical dataset problems)
- Filtering & Selecting Data (high dose, ADR filtering)
- Grouping & Aggregation (mean dose, ADR frequency)
Question Bank Unit 4: Data Handling with Pandas
For detailed information: Basics of Python Programming for Pharmaceutical Sciences