Given a pandas data frame like the following where the column names are the time, the rows are each of the subjects, and the values are probabilities return the column name (or time) the first time the probability is less than .50 for each subject in the data frame. The probabilities are always descending from 1-0 I. have tried looping though the data frame but it is not computationally efficient.
| subject id | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | … | 669 | 670 | 671 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 0.997913 | 0.993116 | 0.989017 | 0.976157 | 0.973078 | 0.968056 | 0.963685 | … | 0.156092 | 0.156092 | 0.156092 |
| 2 | 1 | 0.990335 | 0.988685 | 0.983145 | 0.964912 | 0.958 | 0.952 | 0.946995 | … | 0.148434 | 0.148434 | 0.148434 |
| 3 | 1 | 0.996231 | 0.990571 | 0.985775 | 0.976809 | 0.972736 | 0.969633 | 0.966116 | … | 0.17037 | 0.17037 | 0.17037 |
| 4 | 1 | 0.997129 | 0.994417 | 0.991054 | 0.978795 | 0.974216 | 0.96806 | 0.963039 | … | 0.15192 | 0.15192 | 0.15192 |
| 5 | 1 | 0.997728 | 0.993598 | 0.986641 | 0.98246 | 0.977371 | 0.972874 | 0.96816 | … | 0.154545 | 0.154545 | 0.154545 |
| 6 | 1 | 0.998134 | 0.995564 | 0.989901 | 0.986941 | 0.982313 | 0.972951 | 0.969645 | … | 0.17473 | 0.17473 | 0.17473 |
| 7 | 1 | 0.995681 | 0.994131 | 0.990401 | 0.974494 | 0.967941 | 0.961859 | 0.956636 | … | 0.144753 | 0.144753 | 0.144753 |
| 8 | 1 | 0.997541 | 0.994904 | 0.991941 | 0.983389 | 0.979375 | 0.973158 | 0.966358 | … | 0.158763 | 0.158763 | 0.158763 |
| 9 | 1 | 0.992253 | 0.989064 | 0.979258 | 0.955747 | 0.948842 | 0.942899 | 0.935784 | … | 0.150291 | 0.150291 | 0.150291 |
Goal Output
| subject id | time prob < .05 |
|---|---|
| 1 | 100 |
| 2 | 99 |
| 3 | 34 |
| 4 | 19 |
| 5 | 600 |
| 6 | 500 |
| 7 | 222 |
| 8 | 111 |
| 9 | 332 |
没有评论:
发表评论