连续型表型变量差异检验的结果整理

能够脚本化处理的,一定要脚本化,接入同事差异检验的结果,整理成文章发表的格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re
group_list = 'NS:FS:CS'.split(':')
indice = 'Age:BMI'.split(':')
out = open('Final_Result.NS-FS-CS.mixcon.xls', 'w')
dt = pd.read_table('Result.NS-FS-CS.mixcon.xls', sep = '\t', index_col = 0)
print('Characteristic\t' + '\t'.join(group_list) + '\tP value', file = out)
for x in indice:
sub_dt = dt.loc[x]
line = ''
for group in group_list:
Mean = 'mean('+ group + ')'
Sd = 'sd('+ group + ')'
for colname in sub_dt.index:
if colname == Mean:
group_mean = str(round(sub_dt[colname],2))
line = line + '\t'+ group_mean
if colname == Sd:
group_sd = '('+str(round(sub_dt[colname],2))+')'
line = line + group_sd
print(x +',mean(sd)' + line + '\t%.2e' % dt.loc[x]['pvalue'], file = out) #科学计数法
out.close()

完结撒花,整理是个好习惯,保持进步的首要前提是让自己不要后退;

(✪ω✪)