code: def preprocess(df):
      
  
      def process_row(idx_row):
          idx, row = idx_row
  
          # press-press latency
          tau = 1000 * row[4::3].astype(float).values
          tau = np.r_[np.median(tau), tau]
  
          # duration
          duration = 1000 * row[3::3].astype(float).values
  
          keyname = list('.tie5Roanl') + ['enter']
  
          return pd.DataFrame.from_items([
              ('user', [row['subject']] * 11),
              ('session', [row['sessionIndex'] * 100 + row['rep']] * 11),
              ('tau', tau),
              ('duration', duration),
              ('event', keyname)
          ])
  
      df = pd.concat(map(process_row, df.iterrows())).set_index(['user', 'session'])
      return df
docs: Convert the CMU dataset from row vectors into time/duration row observations