以下是我正在使用的数据框:
patient_id marker_1 marker_2 subtype patient_age patient_gender
0 619681 21.640523 144.001572 0.0 3 female
1 619711 13.787380 162.408932 0.0 15 female
2 619595 22.675580 130.227221 0.0 6 female
3 619990 13.500884 138.486428 0.0 17 male
4 619157 2.967811 144.105985 0.0 6 female
5 619320 5.440436 154.542735 0.0 9 female
6 619663 11.610377 141.216750 0.0 7 female
7 619910 8.438632 143.336743 0.0 5 female
8 619199 18.940791 137.948417 0.0 7 male
9 619430 7.130677 131.459043 0.0 17 female
10 619766 -21.529898 146.536186 0.0 17 female
11 619018 12.644362 132.578350 0.0 12 female
12 619864 26.697546 125.456343 0.0 4 male
13 619273 4.457585 138.128162 0.0 8 female
14 619846 19.327792 154.693588 0.0 12 male
15 619487 5.549474 143.781625 0.0 8 male
16 619311 -4.877857 120.192035 0.0 7 female
17 619804 0.520879 141.563490 0.0 12 female
18 619331 16.302907 152.023798 0.0 16 female
19 619880 0.126732 136.976972 0.0 15 male
20 619428 -6.485530 125.799821 0.0 4 female
21 619554 -13.062702 159.507754 0.0 6 male
22 619072 -1.096522 135.619257 0.0 6 female
23 619095 -8.527954 147.774904 0.0 6 male
24 619706 -12.138978 137.872597 0.0 14 male
25 619708 -4.954666 143.869025 0.0 7 male
26 619693 -1.108051 128.193678 0.0 13 male
27 619975 3.718178 144.283319 0.0 7 female
28 619289 4.665172 143.024719 0.0 9 male
29 619911 -2.343221 136.372588 0.0 7 female
.. ... ... ... ... ...
现在,我正在计算整个数据框的基本统计数据,并计划稍后在
中提取特定值#mean, median, sd of subset data
mean_children = np.mean(children)
med_children = np.median(children)
sd_children = np.std(children)
children_mark1 = [mean_children['marker_1'], med_children['marker_1'], sd_children['marker_1']]
children_mark2 = [mean_children['marker_2'], med_children['marker_2'], sd_children['marker_2']]
children_age = [mean_children['patient_age'], med_children['patient_age'], sd_children['patient_age']]
这是我收到错误的地方。当我打印mean_children['marker_2']
时,我得到121.396907126
所以我不太明白为什么它不允许我将它添加到此向量中。
答案 0 :(得分:2)
np.mean
对整个数据帧求和并返回float
使用
children.mean()
答案 1 :(得分:1)
如果孩子是您的数据框架,我想如果您使用:
children.describe()
或
children.describe().transpose()
你会节省一些时间。