An analysis pipeline that fetches live news article data from the NewsAPI, cleans it, assigns articles into A/B test groups based on headline length, simulates click engagement, and runs a statistical significance test to determine whether headline length affects reader clicks.
You are a data analyst for a media platform experimenting with article headline strategy and post timing. The question being tested:
Do longer headlines drive more clicks than shorter ones?
- Group A (Short): Headlines at or below the median character length
- Group B (Long): Headlines above the median character length
Live data fetched from the NewsAPI — US top headlines, general category, up to 100 results per request.
34 articles × 8 columns (after API fetch; duplicates removed before analysis)
| Column | Type | Description |
|---|---|---|
source |
object | Publisher name (extracted from nested dict) |
author |
object | Article author (10 missing values) |
title |
object | Article headline — primary variable |
description |
object | Short article summary (2 missing) |
url |
object | Article URL |
urlToImage |
object | Thumbnail image URL (2 missing) |
publishedAt |
object | Publication timestamp |
content |
object | Article body excerpt (4 missing) |
| Column | Description |
|---|---|
headline_length |
Character count of title |
group |
A/B group assignment: 'A (Short)' or 'B (Long)' based on median split |
clicks |
Simulated engagement metric (see Simulation section) |
- Fetches up to 100 US top headlines from NewsAPI (
/v2/top-headlines) - Stores raw response as a DataFrame and exports to
raw_news_data.csv
- Inspected data types, shape, and missing values
- Extracted source name from nested dict column
- Added
headline_lengthfeature - Dropped duplicate articles by title
- Imputed missing
authorvalues with the column mode
- Computed median headline length across all articles
- Split articles into Group A (≤ median) and Group B (> median)
- Each group received exactly 17 articles
- Simulated click counts using seeded normal distributions:
- Group A (Short):
Normal(μ=100, σ=25) - Group B (Long):
Normal(μ=150, σ=30)
- Group A (Short):
- Clipped negative values to 0 and rounded to whole numbers
- Headline length statistics by group
- Headline length distribution histogram (with KDE)
- Headline length boxplot by group
- Simulated clicks boxplot by group
- Average clicks bar chart by group
- Top 10 news sources bar chart
- Two-sample independent t-test (
scipy.stats.ttest_ind) on simulated clicks - Significance threshold: α = 0.05
pip install requests pandas numpy matplotlib seaborn scipy| Library | Purpose |
|---|---|
requests |
NewsAPI HTTP calls |
pandas |
Data manipulation |
numpy |
Simulation, group assignment |
matplotlib |
Chart rendering |
seaborn |
Statistical visualisations |
scipy.stats |
Two-sample t-test |
- Ensure a valid NewsAPI key is set in Cell 3 (the current key may expire).
- Install all dependencies listed above.
- Run all cells top-to-bottom — API fetch happens must succeed before downstream cells execute.
- Output files (
raw_news_data.csv,cleaned_articles.csv) and chart images are saved to the working directory.
Note on reproducibility: Simulated click data uses
np.random.seed(42), so results are deterministic given the same article set. However, the article set itself changes with each live API call.
| Metric | Group A (Short) | Group B (Long) |
|---|---|---|
| Articles | 17 | 17 |
| Mean headline length | 66.9 chars | 102.5 chars |
| Simulated mean clicks | ~100 | ~150 |
| T-statistic | -5.382 | |
| P-value | 0.0000065 | |
| Statistically significant? | Yes (p < 0.05) |
See REPORT for the full analysis narrative, interpretation, and limitations.