Welcome to the Clinical Trials Data Accessing and Cleaning repository! This project focuses on demonstrating a complete data wrangling, cleaning, and transformation workflow for healthcare and clinical-trial-style datasets using Python and Pandas.
Real-world clinical data is often messy, missing, or improperly formatted. This repository simulates a real-world scenario where data from multiple sources (patient demographics, treatments, and adverse reactions) must be joined, cleaned, and structurally validated before it is ready for downstream analytics and reporting.
The primary implementation and step-by-step cleaning process is contained in the Jupyter Notebook:
👉 session_28_data_accessing_and_cleaning.ipynb
| File | Description |
|---|---|
patients.csv |
Patient-level demographic information including contact details, addresses, anthropometrics (weight, height, BMI), and exact birthdates. |
treatments.csv |
Treatment records for the main cohort, containing Auralin/Novodra dosage ranges and HbA1c metrics (start, end, change). |
treatments_cut.csv |
Additional treatment records (same schema as treatments.csv) that simulate delayed data or secondary site results. |
adverse_reactions.csv |
Adverse reaction labels (e.g., hypoglycemia, injection site discomfort) keyed by patient name. |
session_28_data_accessing_and_cleaning.ipynb |
End-to-end Jupyter Notebook handling the assessment (visual & programmatic) and cleaning of the dataset. |
The data assessment phase in the notebook identifies and resolves multiple structural (tidiness) and quality issues:
- Denormalized values:
contactcolumn inpatients.csvcontains both phone numbers and email addresses. - Data fragmentation:
treatmentsandtreatments_cutare the same dataset split into two files. - Multiple variables in one column:
auralinandnovodracolumns in treatments contain starting and ending doses combined by a dash (-). - Data merging:
adverse_reactions.csvcontains labels that belong naturally inside thetreatmentstable. - Variables stored as columns instead of rows: The treatment type (
auralinandnovodra) should be a single categorical dimensiontreatment_type, not two separate columns.
- Missing values: Missing demographics in
patients.csv(12 missing values for address/city/state/zip/country/contact), missinghba1c_changein treatment files. - Inconsistent formatting: Mixed state formats (full state names vs. standard 2-letter abbreviations) and varying naming capitalization.
- Data anomalies: Suspected erroneous outliers (e.g., incorrect heights/weights creating impossible BMI values) and duplicate records.
- Placeholder symbols: Dash (
-) representing missing treatment values instead of standardNaNformatting.
The notebook strictly follows a Define → Code → Test standard software engineering pattern.
-
Pre-processing: Loading data, making deep copies (
df.copy()) before applying transformations. -
Standardization:
- Creating derived columns correctly (e.g., parsing phone vs email using regex).
- Unifying string formatting (e.g., lowercasing names, converting state names to standard postal abbreviations).
-
Data imputation and derivation:
- Calculating missing
hba1c_changemetrics using:$$\Delta HbA1c = HbA1c_{start} - HbA1c_{end}$$
- Calculating missing
-
Data structuring:
- Utilizing
pd.melt()and string splitting (.str.split()) to explode dosage ranges intodosage_startanddosage_end. - Concatenating (
pd.concat())treatmentsandtreatments_cut. - Merging (
pd.merge()) the adverse reactions DataFrame smoothly into the primary treatment records.
- Utilizing
To execute the data cleaning pipeline locally, ensure you have the following installed:
- Python 3.10+
pandasnumpyjupyter/jupyterlab
- Clone this repository to your local workspace.
- Open
session_28_data_accessing_and_cleaning.ipynbin VS Code or Jupyter Server. - Select your Python kernel.
- Execute the cells sequentially from top to bottom.
- Review the
.info(),.isnull(), and.duplicated()outputs provided at each checkpoint to see the data quality improve interactively.
This project is intended for educational and demonstrational purposes. The datasets are fictional clinical data representations created strictly for data-cleaning training.