code: def day_counts(index):
      
      # dont affect the original data
      index = index.copy()
  
      if len(index) == 0:
          return pd.Series([], index=index)
  
      timedeltas = (index[1:] - index[:-1]).append(pd.TimedeltaIndex([pd.NaT]))
      timedelta_days = timedeltas.total_seconds() / (60 * 60 * 24)
  
      return pd.Series(timedelta_days, index=index)
docs: Days between DatetimeIndex values as a :any:`pandas.Series`.
  
      Parameters
      ----------
      index : :any:`pandas.DatetimeIndex`
          The index for which to get day counts.
  
      Returns
      -------
      day_counts : :any:`pandas.Series`
          A :any:`pandas.Series` with counts of days between periods. Counts are
          given on start dates of periods.