code: def to_perseus(df, path_or_file, main_columns=None,
          separator=separator,
          convert_bool_to_category=True,
          numerical_annotation_rows = set([])):
      _df = df.copy()
      if not _df.columns.name:
          _df.columns.name = 'Column Name'
      column_names = _df.columns.get_level_values('Column Name')
      annotations = {}
      main_columns = _infer_main_columns(_df) if main_columns is None else main_columns
      annotations['Type'] = ['E' if column_names[i] in main_columns else dtype_to_perseus(dtype)
              for i, dtype in enumerate(_df.dtypes)]
      for i, column in enumerate(_df.columns):
          valid_values = [value for value in _df[column] if value is not None]
          if len(valid_values) > 0 and all(type(value) is list for value in valid_values):
              annotations['Type'][i] = 'M'
              _df[column] = _df[column].apply(lambda xs: ';'.join(str(x) for x in xs))
      if convert_bool_to_category:
          for i, column in enumerate(_df.columns):
              if _df.dtypes[i] is np.dtype('bool'):
                  values = _df[column].values
                  _df[column][values] = '+'
                  _df[column][~values] = ''
      annotation_row_names = set(_df.columns.names) - {'Column Name'}
      for name in annotation_row_names:
          annotation_type = 'N' if name in numerical_annotation_rows else 'C'
          annotations['{}:{}'.format(annotation_type, name)] = _df.columns.get_level_values(name)
      with PathOrFile(path_or_file, 'w') as f:
          f.write(separator.join(column_names) + '\n')
          for name, values in annotations.items():
              f.write('
          _df.to_csv(f, header=None, index=False, sep=separator)