我有一个包含时间序列数据的数据帧,如下所示:
(TP=时间点)
gene number TP1 TP2 TP3 TP4 TP5 TP6
gene1 0.4 0.2 0.1 0.5 0.8 1.9
gene2 0.3 0.05 0.5 0.8 1.0 1.7
....
对于每一行(基因),我想确定其值达到时间序列中最小值4倍大的水平时的TP,附加条件是这个确定的TP必须在最小TP之后。所以,对于基因2,我感兴趣的是TP3而不是TP1(它比TP2的最小值大4倍),因为TP1在序列中比最小TP2早。你知道吗
所以我试图构建的脚本的结果是:
gene1 TP4
gene2 TP3
...
我的数据在numpy数组中。你知道吗
您可以首先创建一个掩码
ma
,并将最小值之前的所有行值设置为False
。接下来,使用此掩码查找最小值后每行中的值,以达到最小值的4倍(由True
表示):然后可以使用
idxmax
从这个布尔数据帧(我称之为df1
)检索第一个True
值的标签:这里有一个方法:
退货:
相关问题 更多 >
编程相关推荐