过滤熊猫系列中的最高值

时间:2020-05-07 18:50:07

标签: python-3.x pandas filter probability

def process():
    active = ACTIVES[0]
    df = pandas.read_csv(f'{active}.csv', index_col='time')
    probs = df.groupby(['time']).candle.apply(lambda g: g.value_counts() / len(g))
    print(probs)

结果:

time       
00:00  put     0.735294
       call    0.264706
00:05  call    0.500000
       put     0.352941
       dogi    0.147059
                 ...   
23:50  call    0.666667
       put     0.333333
23:55  call    0.500000
       put     0.441176
       dogi    0.058824
Name: candle, Length: 718, dtype: float64

现在,我该如何过滤TIME列中的最高值(输入/调用)至少大于或等于0.7,然后过滤下一个TIME等于或大于

示例:

time       
00:00  put     0.735294 #higher then 0.7, but do not include in the final resul because the next TIME (00:05) is not put
       call    0.264706
00:05  call    0.500000
       put     0.352941
       dogi    0.147059

time       
00:00  put     0.735294 #higher then 0.7, and the next TIME is a put and higher or equal a 0.7
       call    0.264706
00:05  put     0.700000
       call    0.300000

“时间”列在5分钟内位于5

UPDATE 01

我到目前为止有什么:

def process():
    active = ACTIVES[0]
    df = pandas.read_csv(f'{active}.csv', index_col='time', parse_dates=True)
    df = df.groupby(['time']).candle.apply(lambda g: g.value_counts() / len(g)).reset_index()

    print(df.query('candle > 0.7'))

打印结果:

                   time level_1    candle
0   2020-05-07 00:00:00     put  0.735294
20  2020-05-07 00:35:00    call  0.718750
58  2020-05-07 01:40:00    call  0.750000
371 2020-05-07 12:35:00     put  0.787879
487 2020-05-07 16:25:00    call  0.742857
625 2020-05-07 20:55:00     put  0.718750
663 2020-05-07 22:15:00    call  0.750000

现在,我该如何遍历行并比较下一个TIME行是否大于5分钟并且level_1是相等方向?

请原谅我的英语

0 个答案:

没有答案