I have a few set of days where the index is based on 30min data from monday to friday. There might some missing dates (Might be because of holidays). But I would like to find the highest from column high
and lowest from column low
for ever past week. Like I am calculating today so previous week high and low is marked in the yellow of attached image.
I tried using rolling, resampling but it's somehow not working. Can anyone help?
CodePudding user response:
If I have understood correctly, the solution should be
- get the week number from the date
- groupby the week number and fetch the max and min number.
- groupby the week fetch max date to get max/last date for a week
- now merge all the dataframes into one based on date key
- Once the steps are done, you could do any formatting as required.
CodePudding user response:
Thanks all for the inputs. Below are the desired output
- Looking for last week (ie from 11th july 22 to 15th july 22) and get the low related to the 30min highest high. which occurred on 12-07-2022 09:15:00
- A new column which populates all the low for last week(30 min interval) with the values 369.2 (green in color) for this week and 370.05(Orange in color) for last week (Whose value is derived as low of the 30min highest high of week 4th july to 8th july)
- there might be missing dates (because of data unavailable) but still for the whole last week 30 min highest high is 376.25 and its corresponding low is 369.2 which needs to be populated for the this df["Previous week corresponding low of the 30min highest high"]
Hope i am bit more clear on the output. I know its bit complex requirement. Desired output shown in 4th column "Previous week corresponding low of the 30min highest high"