count how many times the column ratio is bigger than 0.05 and column dif is between 15 and 30

Question:

Datetime              ratio                  dif
2022-06-09 12:33:00  -0.3861241598107547    -299.50183804712964
2022-06-09 12:34:00 -0.360130489922861  -274.88184087028105
2022-06-09 12:35:00 -0.22108950904852795    -166.02672464097395
2022-06-09 12:36:00 -0.18316426991752388    -135.2928226604197
2022-06-09 12:37:00 -0.09932437001820388    -72.14644129886278
2022-06-09 12:38:00 -0.0820362738010348 -58.58522049972339
2022-06-09 12:39:00 -0.04310125282586597    -30.25449340858836
2022-06-09 12:40:00 -0.48650055935157194    -335.5773828284086
2022-06-09 12:41:00 -0.040251923613339506   -27.620467464237436
2022-06-09 12:42:00 -0.19392674180880734    -132.750611837801
2022-10-10 23:59:59         0                             0

how could i find how many times ratio is bigger than 0.05
and dif is betwwen 15-30 at the same time ?
the dataframe is called frames

Asked By: span_path

||

Answers:

ratio_condition = df['ratio'].abs() > 0.05
dif_condition = (df['dif'].abs() >= 15) & (df['dif'].abs() <= 30)

count = (ratio_condition & dif_condition).sum()
Answered By: Michael Cao
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.