Open alg-jmx opened 3 years ago
counts_dict = {} y = df_new[col_treatment] trt = df_new[col_outcome] for feat in feats: bin_feat = str(feat) + '_bin' counts1_t1 = df_new[(y == 1) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t1'}) counts1_t0 = df_new[(y == 1) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t0'}) counts0_t1 = df_new[(y == 0) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t1'}) counts0_t0 = df_new[(y == 0) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t0'})
counts_dict[feat] = pd.concat([counts1_t1, counts1_t0, counts0_t1, counts0_t0], axis=1).fillna( 0) + 1 # replace any empty slots with zeros (and add 1 to everything)
should be
counts_dict = {} y = df_new[col_outcome] trt = df_new[col_treatment] for feat in feats: bin_feat = str(feat) + '_bin' counts1_t1 = df_new[(y == 1) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t1'}) counts1_t0 = df_new[(y == 1) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t0'}) counts0_t1 = df_new[(y == 0) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t1'}) counts0_t0 = df_new[(y == 0) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t0'})
counts_dict = {} y = df_new[col_treatment] trt = df_new[col_outcome] for feat in feats: bin_feat = str(feat) + '_bin' counts1_t1 = df_new[(y == 1) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t1'}) counts1_t0 = df_new[(y == 1) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t0'}) counts0_t1 = df_new[(y == 0) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t1'}) counts0_t0 = df_new[(y == 0) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t0'})
creating a dataframe with all of these results
should be
counts_dict = {} y = df_new[col_outcome] trt = df_new[col_treatment] for feat in feats: bin_feat = str(feat) + '_bin' counts1_t1 = df_new[(y == 1) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t1'}) counts1_t0 = df_new[(y == 1) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y1t0'}) counts0_t1 = df_new[(y == 0) & (trt == 1)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t1'}) counts0_t0 = df_new[(y == 0) & (trt == 0)][[feat, bin_feat]].groupby(bin_feat).count().rename( columns={feat: 'counts_y0t0'})
creating a dataframe with all of these results