Advertisement
Guest User

Untitled

a guest
Aug 15th, 2022
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. """
  4. data=                                                                          
  5.      Date     High   Low    failure                                            
  6. 0     12/01    90     60      0                                                
  7. 1     12/03    88     61      0
  8. 2     12/05    76     38      15
  9. 3     12/07    70     36      17
  10. 4     12/09    81     56      2                                                
  11. """
  12.  
  13. def tail_min(df):
  14.     return df.tail(2).min()
  15.  
  16. def tail_max(df):
  17.     return df.tail(2).max()
  18.  
  19. indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=3)
  20. data["rolling_High"] = data["High"].rolling(window = indexer, min_periods=1).apply(tail_max)
  21. data["rolling_Low"] =  data["Low"].rolling(window = indexer, min_periods=1).apply(tail_min)
  22.  
  23. #failure > 10 and next 2 columns max and min
  24. data.loc[data["failure"] > 10, ["failure","rolling_High", "rolling_Low"]]
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement