I have a numpy array that looks like below. I wanted to pull out the data day by day and run a function on that. I tried doing it brute force (code snippet below) but that does not quite work either. I'm sure there is a function of some sort that will just pull out the parts of array that correspond to particular day and pass that subset to my function:
while i < len(stoch_osc):
print('value of i is: ', i, ' Valuate of i delta is: ', i delta)
print(stoch_osc[i:i delta, ])
some_function(stoch_osc[i:i delta, ])
i = i delta
stoch_osc is an array that looks like this (timestamp in datetime
followed by a bunch of values). I get below output by doing print(stoch_osc):
[[Timestamp('2021-10-01 00:32:00') 4276.0 4276.0 ... 4275.25 83 64.28]
[Timestamp('2021-10-01 00:33:00') 4275.5 4276.25 ... 4276.25 105 78.57]
[Timestamp('2021-10-01 00:34:00') 4276.25 4276.75 ... 4275.5 10167.85]
[Timestamp('2021-10-04 01:31:00') 4331.0 4333.0 ... 4332.25 582 71.21]]
CodePudding user response:
This code will loop over the input and will add all the items of the input to the list data_of_day that have the same day as given.
day = "04"
data_of_day = [input[i] for i in range(len(input)) if input[i][0][8:10] == day]
print(data_of_day)
