How do I Obtain Three days High,Low,Close of Python DataFrame below by skipping the not available Dates in DataFrame?

Viewed 46

This is the DataFrame That I am working on

 -      Date     Open    High    Low   Close
1. 01-08-2019 | 97.85 | 98.45 | 96.40 |97.25
2. 02-08-2019 | 97.15 | 98.95 | 96.75 |98.15
3. 05-08-2019 | 98.30 | 98.70 | 94.30 |95.65
4. 06-08-2019 | 95.75 | 97.75 | 95.20 |97.05
5. 07-08-2019 | 96.80 | 97.70 | 96.05 |96.90
6. 08-08-2019 | 97.40 | 98.90 | 96.55 |97.40
7. 09-08-2019 | 97.20 | 98.10 | 96.65 |97.30
8. 12-08-2019 | 97.20 | 97.25 | 93.40 |93.75
9. 13-08-2019 | 93.70 | 96.60 | 93.15 |96.35
- ................

After running this code:

df.set_index('Date').asfreq('D').resample('3D').agg({'High':'max','Low': 'max','Close':'max'})

The result calculated was max of 01-08-2019, 02-08-2019, 03-08-2019. But on 03-08-2019 I had no data in original DataFrame. Code takes 03-08-2019 as zero But instead of considering 03-08-2019 I want my code to calculate by taking Third day as 05-08-2019.

Link to data [1]: https://drive.google.com/file/d/1OzRUHDMwh6xEp2ajdq3-rI5ddseGLhbV/view?usp=sharing

1 Answers

you don't then need to resample your data:

df.groupby(df.index // 3).agg({'High':'max','Low': 'max','Close':'max', 'Date': 'first'})
Related