How to make a calculation with a fixed reference that shifts every day in Pandas?

Viewed 39

My data is intraday stock prices data, multiple days. This is a simplified version:

                     Last                                                   
2015-01-02 08:30:00  2035.00
2015-01-02 10:30:00  2038.25                    
2015-01-02 15:15:00  2025.25  
2015-01-05 08:30:00  2020.25  
2015-01-05 10:30:00  2010.75                      
2015-01-05 15:15:00  2015.00                  
2015-01-06 08:30:00  1988.00 
2015-01-06 10:30:00  1990.25                     
2015-01-06 15:15:00  1970.00

Given that in the data, every day, the last row is at 15:15:00, how can I take the difference (15:15:00 Row - Last), for every row per day. Here's the desired output.

                     Last      Dif                                             
2015-01-02 08:30:00  2035.25  -10 
2015-01-02 10:30:00  2038.25  -13                  
2015-01-02 15:15:00  2025.25   0
2015-01-05 08:30:00  2020.25  -5.25
2015-01-05 10:30:00  2010.00   5                   
2015-01-05 15:15:00  2015.00   0               
2015-01-06 08:30:00  1988.00  -18
2015-01-06 10:30:00  1990.25  -20.25                    
2015-01-06 15:15:00  1970.00   0
1 Answers
Related