code: def time_segments_aggregate(X, interval, time_column, method=['mean']):
      
      if isinstance(X, np.ndarray):
          X = pd.DataFrame(X)
  
      X = X.sort_values(time_column).set_index(time_column)
  
      if isinstance(method, str):
          method = [method]
  
      start_ts = X.index.values[0]
      max_ts = X.index.values[-1]
  
      values = list()
      index = list()
      while start_ts <= max_ts:
          end_ts = start_ts + interval
          subset = X.loc[start_ts:end_ts - 1]
          aggregated = [
              getattr(subset, agg)(skipna=True).values
              for agg in method
          ]
          values.append(np.concatenate(aggregated))
          index.append(start_ts)
          start_ts = end_ts
  
      return np.asarray(values), np.asarray(index)
docs: Aggregate values over fixed length time segments.