问卷数据指标计算(编码记忆点)
数据准备和样本筛选
按数据框的某几列计算简单统计量生成新列(自动处理缺失值)
#最小值
k['CHA_12'] = k['C10.1']-k[['C10.2_SQ1','C10.2_SQ2','C10.2_SQ3','C10.2_SQ4','C10.2_SQ5','C10.2_SQ6']].mean(axis=1)
#最大值
k['max']= k[['C10.2_SQ1','C10.2_SQ2','C10.2_SQ3','C10.2_SQ4','C10.2_SQ5','C10.2_SQ6']].max(axis=1)
#计数,非空值的数目
ks['count']= ks[['C10.2_SQ1','C10.2_SQ2','C10.2_SQ3','C10.2_SQ4','C10.2_SQ5','C10.2_SQ6']]