You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.4 KiB
Python

import pandas as pd
# 读取新表
df_feature = pd.read_excel("feature.xlsx")
# 父亲教养方式数字化
df_feature['父亲教养方式数字化'] = df_feature['父亲教养方式'].apply(lambda x: 0.59 if x == '温暖与理解' else 0.46)
# 母亲教养方式数字化
df_feature['母亲教养方式数字化'] = df_feature['母亲教养方式'].apply(lambda x: 0.69 if x == '温暖与理解' else 0.56)
# 自评家庭经济条件数字化
df_feature['自评家庭经济条件数字化'] = df_feature['自评家庭经济条件'].apply(lambda x: 0.54 if x in ['贫困', '较差'] else 0.47)
# 有无心理治疗(咨询)史数字化
df_feature['有无心理治疗(咨询)史数字化'] = df_feature['心理治疗(咨询)史'].apply(lambda x: 0.09 if x in ['', '没有'] else 0.21)
# 强迫症状数字化
df_feature['强迫症状数字化'] = df_feature['强迫症状'] / 4
# 人际关系敏感数字化
df_feature['人际关系敏感数字化'] = df_feature['人际关系敏感'] / 4
# 抑郁症状数字化
df_feature['抑郁症状数字化'] = df_feature['抑郁'] / 4
# 计算多因子症状
df_feature['多因子症状'] = df_feature[['躯体化', '强迫症状', '人际关系敏感', '抑郁', '焦虑', '敌对', '恐怖', '偏执', '精神病性', '其他']].apply(lambda x: sum(x > 3.0) / 10, axis=1)
# 保存处理后的表
df_feature.to_excel("feature_processed.xlsx", index=False)