ComeçarComece de graça

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 senator
  • diff_days: the duration of the senator in office
  • observed: 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.

Este exercício faz parte do curso

Survival Analysis in Python

Ver curso

Instruções do exercício

  • Fit the KaplanMeierFitter instance kmf 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Fit Kaplan-Meier estimator
____(____, ____, label='British Columbia')

# Plot survival function on senator_fig
____

# Display the figure
____
Editar e executar o código