title: Rolling mean over the last n-days with if statement
body: <p>I have the following dataframe:</p>
  
  <pre><code>entry_time_flat           route_id      time_slot      duration    n_of_trips 
  
  2019-09-02 00:00:00           1_2            0-6          10           29
  2019-09-04 00:00:00           3_4            6-12         15           10
  2019-09-06 00:00:00           1_2            0-6          20           30    
  2019-09-06 00:00:00           1_2           18-20         43           30
  ...
  </code></pre>
  
  <p>I would like to compute the mean value of "duration" - creating a new feature - over the last n-days (n_days = 30), with the following condition:</p>
  
  <pre><code>if "n_of_trips" &gt;= 30:
      mean of "duration", over the last 30 days and all the past transactions, grouping by  "route_id" &amp; "time_slot" 
  else:
      mean of "duration", over the last 30 days and all the past transactions, grouping by "route_id" only
  </code></pre>
  
  <p>Unfortunately, splitting the dataframe into two chunks (>= and &lt; 30 n_of_trips) would not yield to an acceptable result since all transactions must be included when computing mean;</p>
  
  <p>How can I implement an if-statement while computing rolling mean over the last n-days?</p>