code: def moving_average(self, sampling_period,
                         window_size=None,
                         start=None, end=None,
                         placement='center',
                         pandas=False):
          
          start, end, mask = self._check_boundaries(start, end)
  
          # default to sampling_period if not given
          if window_size is None:
              window_size = sampling_period
  
          sampling_period = \
              self._check_regularization(start, end, sampling_period)
  
          # convert to datetime if the times are datetimes
          full_window = window_size * 1.  # convert to float if int or do nothing
          half_window = full_window / 2.  # divide by 2
          if (isinstance(start, datetime.datetime) and
                  not isinstance(full_window, datetime.timedelta)):
              half_window = datetime.timedelta(seconds=half_window)
              full_window = datetime.timedelta(seconds=full_window)
  
          result = []
          current_time = start
          while current_time <= end:
  
              if placement == 'center':
                  window_start = current_time - half_window
                  window_end = current_time + half_window
              elif placement == 'left':
                  window_start = current_time
                  window_end = current_time + full_window
              elif placement == 'right':
                  window_start = current_time - full_window
                  window_end = current_time
              else:
                  msg = 'unknown placement "{}"'.format(placement)
                  raise ValueError(msg)
  
              # calculate mean over window and add (t, v) tuple to list
              try:
                  mean = self.mean(window_start, window_end)
              except TypeError as e:
                  if 'NoneType' in str(e):
                      mean = None
                  else:
                      raise e
              result.append((current_time, mean))
  
              current_time += sampling_period
  
          # convert to pandas Series if pandas=True
          if pandas:
  
              try:
                  import pandas as pd
              except ImportError:
                  msg = "can't have pandas=True if pandas is not installed"
                  raise ImportError(msg)
  
              result = pd.Series(
                  [v for t, v in result],
                  index=[t for t, v in result],
              )
  
          return result
docs: Averaging over regular intervals