madhavt madhavt - 1 year ago 92
Python Question

float object has no attribute __getitem__ [Looked elsewhere but haven't been able to find anything applicable]

Here is the data frame i'm working with:

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
.. ... ... ... ... ...


Now, I'm calculating basic statistics of the entire data frame and plan to extract specific values later on

#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']]


This is where I get the error. When I print out
mean_children['marker_2']
I get
121.396907126
so i'm not quite understanding why it won't allow me to add it to this vector.

Answer Source
np.mean

Sums entire dataframe and returns float

Use

children.mean()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download