code: def time_segments_average(X, interval, value_column, time_column):
      
      start_ts = X[time_column].iloc[0]   # min value
      end_time = X[time_column].iloc[-1]  # max value in dataframe
      accepted_points = []
      while start_ts < end_time:
          # average the values between start_ts, [start_ts + timedelta (e.g. 6hrs)]
          upper_ts = start_ts + interval
          mask = (X[time_column] > start_ts) & (X[time_column] <= upper_ts)
          average_value = X.loc[mask][value_column].mean(skipna=True)
  
          accepted_points.append([start_ts, average_value])
          start_ts = upper_ts  # update the timestamp
  
      return pd.DataFrame(accepted_points, columns=[time_column, value_column])
docs: function that aggregates data in a pandas dataframe by averaging over a given interval.
              it starts averaging from the smallest timestamp in the dataframe and ends at the
              largest timestamp. assumes the input is timeseries sorted.
          args:
              X (pandas.dataframe): a pandas dataframe which has 'timestamp'
                  and 'value' columns, and is sorted based on timestamp. the timestamp
                  column is in unix format (in seconds).
              interval (int): an integer denoting the number of seconds
                  in the desired interval.
              value_column (string): name of column that has the value field.
              time_column (string): name of column that has the time field.
          returns:
              pandas.dataframe: a pandas dataframe with two colums
                  ('timestamp' and 'value'), where each `timestamp` is the starting time of
                  an interval and the `value` is the result of aggregation.