 # Column and Rows condition criteria

Hello all,
My first post here, I am currently working on developing a code in Python to give me range at particular time for a particular stock or index (in this case the Nasdaq). I’ve been able so far to create a new column that will generate the range as well as the mean for close price, however…is two other things I would like to do, but not sure how can I approach, try some loops , but honestly I am stuck:

1. I would like to be able to look through nq[‘Range’] column base on let say condition for nq[‘Time’] == 9:30:00 …and take all those values meeting that condition and calculate the mean.
2.The other part I am trying to accomplish to look create condition for a range of time to get highest and lowest count at paritcular time…for example of all days…how many times the lowest was at each time from a particular time to another…
here is what I got so far
from datetime import datetime, timedelta

import pandas as pd

import numpy as np

#convert column Time to datetime

#times = pd.to_timedelta(nq[‘Time’])

#nq[‘Time’] = times

#Determine range for the bar

nq[‘Range’] =nq[‘High’] - nq[‘Low’]

#Mean of the Range

nq[‘range_mean’] = nq[‘Range’].rolling(100).mean().round(2)

#Standard Deviation

nq[‘range_std’] = nq[‘Range’].std().round(2)

Output:

``````Date     Time      Open      High       Low     Close  Range  range_mean  range_std
``````

0 1/4/2021 9:30:00 12950.22 12950.22 12927.58 12928.11 22.64 NaN 4.25
1 1/4/2021 9:31:00 12925.52 12934.50 12923.96 12927.44 10.54 NaN 4.25
2 1/4/2021 9:32:00 12928.05 12928.05 12916.80 12917.13 11.25 NaN 4.25
3 1/4/2021 9:33:00 12916.82 12916.82 12903.10 12904.58 13.72 NaN 4.25
4 1/4/2021 9:34:00 12904.79 12912.40 12903.54 12907.91 8.86 NaN 4.25

Ok, I’ve been searching…and i tried this
from datetime import datetime, timedelta

import pandas as pd

import numpy as np

#convert column Time to datetime

#times = pd.to_timedelta(nq[‘Time’])

#nq[‘Time’] = times

#Determine range for the bar

nq[‘Range’] =nq[‘High’] - nq[‘Low’]

#Mean of the Range

nq[‘range_mean’] = nq[‘Range’].rolling(100).mean().round(2)

#Standard Deviation

nq[‘range_std’] = nq[‘Range’].std().round(2)

print(nq.loc[nq[‘Time’]==‘09:30:00’,‘Range’].rolling(30).mean().round(2))
but I get this output

Series(, Name: Range, dtype: float64)

any thoughts ? Thanks