code: def predict_expectation(self, X):
          r
          subjects = _get_index(X)
          v = self.predict_survival_function(X)[subjects]
          return pd.DataFrame(trapz(v.values.T, v.index), index=subjects)
docs: r"""
          Compute the expected lifetime, :math:`E[T]`, using covariates X. This algorithm to compute the expectation is
          to use the fact that :math:`E[T] = \int_0^\inf P(T > t) dt = \int_0^\inf S(t) dt`. To compute the integral, we use the trapizoidal rule to approximate the integral.
  
          Caution
          --------
          However, if the survival function doesn't converge to 0, the the expectation is really infinity and the returned
          values are meaningless/too large. In that case, using ``predict_median`` or ``predict_percentile`` would be better.
  
          Parameters
          ----------
  
          X: numpy array or DataFrame
              a (n,d) covariate numpy array or DataFrame. If a DataFrame, columns
              can be in any order. If a numpy array, columns must be in the
              same order as the training data.
  
          Returns
          -------
          expectations : DataFrame
  
          Notes
          -----
          If X is a DataFrame, the order of the columns do not matter. But
          if X is an array, then the column ordering is assumed to be the
          same as the training dataset.
  
          See Also
          --------
          predict_median
          predict_percentile