code: def to_csv(self, sep=',', path=None):
          
          stats = self._stats()
  
          data = []
          first_row = ['Stat', self.name]
          data.append(sep.join(first_row))
  
          for stat in stats:
              k, n, f = stat
  
              # blank row
              if k is None:
                  row = [''] * len(data[0])
                  data.append(sep.join(row))
                  continue
              elif k == 'rf' and not type(self.rf) == float:
                  continue
  
              row = [n]
              raw = getattr(self, k)
              if f is None:
                  row.append(raw)
              elif f == 'p':
                  row.append(fmtp(raw))
              elif f == 'n':
                  row.append(fmtn(raw))
              elif f == 'dt':
                  row.append(raw.strftime('%Y-%m-%d'))
              else:
                  raise NotImplementedError('unsupported format %s' % f)
  
              data.append(sep.join(row))
  
          res = '\n'.join(data)
  
          if path is not None:
              with open(path, 'w') as fl:
                  fl.write(res)
          else:
              return res
docs: Returns a CSV string with appropriate formatting.
          If path is not None, the string will be saved to file
          at path.
  
          Args:
              * sep (char): Separator
              * path (str): If None, CSV string returned. Else file written
                  to specified path.