def ResampleDivorceCurveByDecade(resps): for i in range(41): samples = [thinkstats2.ResampleRowsWeighted(resp) for resp in resps] sample = pandas.concat(samples, ignore_index=True) groups = sample.groupby('decade') if i == 0: survival.AddLabelsByDecade(groups, alpha=0.7) EstimateSurvivalByDecade(groups, alpha=0.1) thinkplot.Save(root='survival7', xlabel='years', axis=[0, 28, 0, 1])
def ResampleDivorceCurveByDecade(resps): """Plots divorce curves for each birth cohort. resps: list of respondent DataFrames """ for i in range(41): samples = [thinkstats2.ResampleRowsWeighted(resp) for resp in resps] sample = pandas.concat(samples, ignore_index=True) groups = sample.groupby('decade') if i == 0: survival.AddLabelsByDecade(groups, alpha=0.7) EstimateSurvivalByDecade(groups, alpha=0.1) thinkplot.Save(root='survival6', xlabel='years', axis=[0, 28, 0, 1])
def DivorceCurveDecade(dfs): """ plot divorce curves @param: dfs - list of dataframes (hitched_) """ for i in range(50): samples = [thinkstats2.ResampleRowsWeighted(df) for df in dfs] sample = pd.concat(samples, ignore_index=True, sort=True) groups = sample.groupby('decade') if i == 0: survival.AddLabelsByDecade(groups, alpha=0.5) EstSurvivalDecade(groups, alpha=0.1) thinkplot.Config(xlabel='Years', ylabel='Fraction undivorced', axis=[0, 28, 0, 1])