Hungarian physician Dr. Ignaz Semmelweis worked at the Vienna General Hospital with childbed fever patients. Childbed fever is a deadly disease affecting women who have just given birth, and in the early 1840s, as many as 10% of the women giving birth died from it at the Vienna General Hospital. Dr.Semmelweis discovered that it was the contaminated hands of the doctors delivering the babies, and on June 1st, 1847, he decreed that everyone should wash their hands, an unorthodox and controversial request; nobody in Vienna knew about bacteria.
You will reanalyze the data that made Semmelweis discover the importance of handwashing and its impact on the hospital and the number of deaths.
The data is stored as two CSV files within the data
folder.
data/yearly_deaths_by_clinic.csv
contains the number of women giving birth at the two clinics at the Vienna General Hospital between the years 1841 and 1846.
Column | Description |
---|---|
year | Years (1841-1846) |
births | Number of births |
deaths | Number of deaths |
clinic | Clinic 1 or clinic 2 |
data/monthly_deaths.csv
contains data from 'Clinic 1' of the hospital where most deaths occurred.
Column | Description |
---|---|
date | Date (YYYY-MM-DD) |
births | Number of births |
deaths | Number of deaths |
# Imported libraries
import pandas as pd
import matplotlib.pyplot as plt
# Start coding here
# Use as many cells as you like!
df = pd.read_csv('data/yearly_deaths_by_clinic.csv')
df.shape
# Proportion of deaths per clinic
df["proportion"] = df["deaths"] / df["births"]
df.groupby(["year", "clinic"])["proportion"].mean().sort_values(ascending=False)[:10].sort_values(ascending=True)\
.plot(kind="barh", ylabel="Year/Clinic", xlabel="Proportion of Deaths/Births")
highest_year = 1842
# Pre/Post Handwashing
df = pd.read_csv('data/monthly_deaths.csv', parse_dates = ['date'])
print(df.dtypes)
handwashing_date = pd.to_datetime('1847-06-01')
print(handwashing_date)
df["handwashing_started"] = False
df.loc[df["date"] < handwashing_date, "handwashing_started"] = False
df.loc[df["date"] >= handwashing_date, "handwashing_started"] = True
df["proportion"] = df["deaths"] / df["births"]
monthly_summary = df.groupby('handwashing_started')["proportion"].mean().reset_index()
monthly_summary
# Confidence interval
from scipy import stats
before = df.loc[df["handwashing_started"] == False]
after = df.loc[df["handwashing_started"] == True]
# Calculate the difference in means
mean_difference = after["proportion"].mean() - before["proportion"].mean()
# Calculate the standard errors
std_pre = before["proportion"].std() / (len(before) ** 0.5)
std_post = after["proportion"].std() / (len(after) ** 0.5)
# Degrees of freedom
df_pre = len(before) - 1
df_post = len(after) - 1
# Standard error of the difference in means
se_difference = (std_pre**2 + std_post**2) ** 0.5
# Confidence interval using the t-distribution
confidence_interval = stats.t.interval(0.95, df=min(df_pre, df_post), loc=mean_difference, scale=se_difference)
# Store the result in a pandas series
confidence_interval = pd.Series(confidence_interval, index=['lower_bound', 'upper_bound'])
print(confidence_interval)