May-10-2021, 05:23 PM
Hello everyone, I am just running a loop through a data frame. Here is an example of it.
So I am looping through. I know how to do if the current row high is greater then previous row high, print "Hello". I know how to have the loop "access" the columns.
But what if I want my loop to do something based on the index? Like if the timestamp is greater then 09:54:00 than "do something"?
How would I do that?
Heres an example of how I am just accessing the columns.. obviously I have renamed the DF.. but just showing you the simplicity of the code.
Output:{'NQ':
Date High Low Close MA_50 Return
20210507 09:54:00 13742.50 13729.00 13729.25 13718.226 0.0
20210507 09:54:30 13732.25 13712.25 13716.75 13718.160 0.0
My dataframe is called NQ, and the index is Date with High, Low, Close, MA_50, and Return being columns. So I am looping through. I know how to do if the current row high is greater then previous row high, print "Hello". I know how to have the loop "access" the columns.
But what if I want my loop to do something based on the index? Like if the timestamp is greater then 09:54:00 than "do something"?
How would I do that?
Heres an example of how I am just accessing the columns.. obviously I have renamed the DF.. but just showing you the simplicity of the code.
if esFutures[ticker]["High"][i] <= esFutures[ticker]["High"][i-1]: