Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pre Processing a dataframe
#1
Hi All,

Trying to get my head around Pandas and backtesting.py at the moment so apologies for the simple question...

I have the following 1 minute data for the DAX

[Image: njffjyW.png]

What I am wanting to do is generate 2 new columns; Hourly Open and Daily Open.

Hourly Open - I would like to fill this column with the open price of the current hour.... so at 11:00 Open = 12888, I would like each subsequent column to be filled with that open price UNTIL the next hour commences at 12:00....

Daily Open - I would like to do the same but fill the column with the open price at 08:00 all day Until the next day at 08:00

If anyone could pls help regarding how I can achieve this I'd be so appreciative! I swear my jupyter notebook is just spitting out error messages to annoy me now :)

hmmmm - maybe I should have posted this is Data Sciences forum. Sorry!
Reply
#2
Just wanted to add an image of what I was after to try to clarify the post above...

Seriously not getting anywhere on my own with this. So would definitely appreciate some help :)

Thanks!

Just for clarity - this is a mockup I created in Google Sheets. The data is already in pandas, I just needed to mock something up to display what I was aiming to achieve.

[Image: 9ul04.png]
Reply
#3
so I assume data (by your image) is in excel format.
so you will need to:
  1. import pandas
  2. read excel as data frame using: https://pandas.pydata.org/docs/reference...excel.html
  3. And then you have a dataframe that you can do with as you please.
Reply
#4
(Jul-07-2022, 10:00 PM)Larz60+ Wrote: so I assume data (by your image) is in excel format.
so you will need to:
  1. import pandas
  2. read excel as data frame using: https://pandas.pydata.org/docs/reference...excel.html
  3. And then you have a dataframe that you can do with as you please.


Thanks Larz60 - I've already imported into Pandas. That's where my lack of knowledge starts kicking in!

I am trying to find a way to fill the new columns I've generated with the Open price at the Market Session Open, and then also at each Hourly open...

I've tried at_time(), I've tried resampling the data into both houlry and Daily but I get am lost as to how to accomplish what I need.

I took an image of how Id like the data to eventually look like after I struggled getting the dataframe to format priperly with the wysywig code editor on the forum post ;)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020