code: def export_events(self, filename, evt_type):
          
          filename = splitext(filename)[0] + '.csv'
          headings_row = ['Index',
                         'Start time',
                         'End time',
                         'Stitches',
                         'Stage',
                         'Cycle',
                         'Event type',
                         'Channel']
          
          events = []
          for et in evt_type:
              events.extend(self.get_events(name=et))
              
          events = sorted(events, key=lambda evt: evt['start'])
          
          if events is None:
              lg.info('No events found.')
              return
          
          with open(filename, 'w', newline='') as f:
              lg.info('Writing to ' + str(filename))
              csv_file = writer(f)
              csv_file.writerow(['Wonambi v{}'.format(__version__)])
              csv_file.writerow(headings_row)
              
              for i, ev in enumerate(events):
                  csv_file.writerow([i + 1,
                                     ev['start'],
                                     ev['end'],
                                     0,
                                     ev['stage'],
                                     '',
                                     ev['name'],
                                     ', '.join(ev['chan']),
                                     ])
docs: Export events to CSV
          
          Parameters
          ----------
          filename : str
              path of export file
          evt_type : list of str
              event types to export