Senators' terms in office
You want to compare if senators from Quebec tend to serve a different term length than those from British Columbia. One simple method is to plot their Kaplan-Meier survival functions on the same graph.
The DataFrame containing British Columbia senator term durations information is called bc_df
. It contains columns
name
: the name the of senatordiff_days
: the duration of the senator in officeobserved
: whether the end of the term is observed (1 or 0)
The survival curve of Quebec senators has been plotted on a pyplot
object called senator_fig
, and a KaplanMeierFitter
instance called kmf
has been created.
Additionally, the pandas
package is loaded as pd
, the KaplanMeierFitter
class is imported from lifelines
, and the pyplot
module has been import from matplotlib
as plt
.
This exercise is part of the course
Survival Analysis in Python
Exercise instructions
- Fit the
KaplanMeierFitter
instancekmf
to British Columbia senators' term durations. - Plot the British Columbia senators' survival curve on the same figure as that of Quebec senators.
- Display the figure.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Fit Kaplan-Meier estimator
____(____, ____, label='British Columbia')
# Plot survival function on senator_fig
____
# Display the figure
____