Python Forum

Full Version: day HIGH/LOW studies on 1-min S&P futures data.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to do a day HIGH/LOW studies on 1-min S&P futures data.

I have 2 questions.

1) How could I print the day HIGH / LOW for each day
2) How could I print the day HIGH / LOW for the first hour of trading


Thanks a lot in advance.

[Image: 49979016508_ac2c704a2f_c.jpg]
What are column types (date and time)?

If they are of DateTime dtype (datetime64[ns]), you can do this using groupby, e.g.

df.groupby('date')['high'].max() # get max values of 'high' column for each day
df.groupby('date')['high'].min() # get min values of 'high' column for each day

df.groupby([df.date, df.time.dt.hour])['high'].max() # get max values of 'high' column for each hour (during the day)
(Jun-07-2020, 10:13 AM)scidam Wrote: [ -> ]What are column types (date and time)?

If they are of DateTime dtype (datetime64[ns]), you can do this using groupby, e.g.

df.groupby('date')['high'].max() # get max values of 'high' column for each day
df.groupby('date')['high'].min() # get min values of 'high' column for each day

df.groupby([df.date, df.time.dt.hour])['high'].max() # get max values of 'high' column for each hour (during the day)

Thanks scidam for your quick reply.

I am kind of stuck here. I want to have the output displayed all in 2 lines day by day like the following.


Date, Time, High
Date, Time, Low



How could I write it in such a way to achieve that ? many thanks. I went thru many Youtube videos on groupby, but I am not able to find groupby with multiple columns outputs with different calculation criteria(Max of High and Min of Low in this case.)

[Image: 49979772158_557aed747e_z.jpg]

data type originally

[Image: 49980331116_33822ee0e8_z.jpg]

Then I converted the Date and Time to datetime64 format. Not sure if I made it better or worse?

[Image: 49980598277_9b1e927e59_c.jpg]
I need to print the day HIGH / LOW for each day and the time it occurred. I can't find a way to retrieve the corresponding time using the groupby function.

Can someone please help ?