Prepares the data in CSV format
501199
def format_csv(self, delim=',', qu='"'):
        
        res = qu + self.name + qu + delim
        if self.data:
            for d in self.data:
                res += qu + str(d) + qu + delim
        return res + '\n'
925273
def to_csv(format = :long)
      output = ''
      
      columns = []
      # only output
      case format
      when :long
        columns.concat([@id, @updated, @title])
      end
      
      # output all dimensions
      columns.concat(@dimensions.map {|d| d.value})
      
      # output all metrics
      columns.concat(@metrics.map {|m| m.value})

      output = CSV.generate_line(columns)      
      return output
    end
938632
def to_csv(options={})
      CSV.generate(options) do |csv|
        csv << scope.attributes
        csv << attributes_hash.values
      end
    end
887651
function csv(input, delimiter) {
  if (!input) return []
  delimiter = delimiter || ','

  var lines  = toArray(input, /\r?\n/)
  var first  = lines.shift()
  var header = toArray(first, delimiter)

  var data = lines.map(function(line) {
    var row = toArray(line, delimiter)
    return toObject(row, header)
  })

  return data
}
1325996
def gen_csv(sc, filename, field_list, source, filters):
    '''
    '''

    # First thing we need to do is initialize the csvfile and build the header
    # for the file.
    datafile = open(filename, 'wb')
    csvfile = csv.writer(datafile)
    header = []
    for field in field_list:
        header.append(fields.fields[field]['name'])
    csvfile.writerow(header)

    debug.write('Generating %s: ' % filename)
    # Next we will run the Security Center query.  because this could be a
    # potentially very large dataset that is returned, we don't want to run out
    # of memory.  To get around this, we will pass the query function the writer
    # function with the appropriate fields so that it is parsed inline.
    fparams = {'fobj': csvfile, 'flist': field_list}
    sc.query('vulndetails', source=source, 
             func=writer, func_params=fparams, **filters)
    debug.write('\n')

    # Lastly we need to close the datafile.
    datafile.close()
837495
def _format_output(content, typ):
    

    if "csv" in str(typ):
        return _format_csv(content, delimiter=",")

    if "tsv" in str(typ):
        return _format_csv(content, delimiter="\t")

    return content
267554
def csv(self):
        
        lines = self._parsecsv(self.raw)

        # set keys from header line (first line)
        keys = next(lines)

        for line in lines:
            yield dict(zip(keys, line))
869544
def _write_data_csv(csv_data):
    
    logger_excel.info("enter write_data_csv")
    # Loop for each file and data that is stored
    for file in csv_data:
        for filename, data in file.items():
            # Make sure we're working with the right data types before trying to open and write a file
            if isinstance(filename, str) and isinstance(data, list):
                try:
                    with open(filename, 'w+') as f:
                        w = csv.writer(f)
                        for line in data:
                            w.writerow(line)
                except Exception:
                    logger_excel.debug("write_data_csv: Unable to open/write file: {}".format(filename))

    logger_excel.info("exit write_data_csv")
    return
1294726
def save_csv(data,  # type: Iterable[Tuple[Union[str, int], ...]]
             headers,  # type: Iterable[str]
             file  # type: TextIO
             ):
    # type: (...) -> None
    

    print(','.join(headers), file=file)
    writer = csv.writer(file)
    writer.writerows(data)
1234416
def csv(self, output):
        """"""
        import csv
        csvwriter = csv.writer(self.outfile)
        csvwriter.writerows(output)
915597
def map_to_csv(fields, delimiter=","):
    

    def _list_to_csv(l):
        """
        Util function to overcome the use of files by in-memory io buffer

        :param l:
        :return:
        """
        io_file = io.StringIO()
        writer = csv.writer(io_file, quoting=csv.QUOTE_NONNUMERIC, lineterminator='', delimiter=delimiter)
        writer.writerow(l)
        return io_file.getvalue()

    def _app(current_tuple, e=None):
        if e is not None:
            return None, e
        csv_list = []
        for f in fields:
            if f in current_tuple:
                csv_list.append(current_tuple[f])
            else:
                e.update({"output": "expected field {} not found".format(f)})
                return None, e
        return _list_to_csv(csv_list), e
    if fields is None or len(fields) == 0:
        return fixed_input(None, "no fields provided, cannot proceed without order")
    return _app
1157379
def unisim_csv_formatting(path, fname):
    
    with open(path+fname, 'r') as fobj:
        data = fobj.readlines()
        header = data[9].split(",")[:-1]
        unit_of_measures = data[10].split(",")[:-1]
    data = pd.read_csv(path+fname,
                       skiprows=10,
                       index_col=0,
                       usecols=(range(0, len(header))),
                       na_values=('Shutdown', 'Bad',
                                  'I/O Timeout', 'Scan Timeout'))
    data.columns = header[1:]
    data.unit = unit_of_measures[1:]
    return data
292774
function csvToMapping(csvString) {
  const lines = csvString.split(/\n|\r|\r\n/);
  const header = lines.shift().split(',');
  const key = header.shift();
  const now = new Date();
  const headerIdx = [];
  const fields = [];
  header.forEach((h, i) => {
    if (h === '') return;
    headerIdx.push(i);
    fields.push({key: h, format: 'text'});
  });
  const mapping = {
    created: now.toString(),
    fields: fields,
    key: key,
    mapping: {}
  };
  lines.forEach(line => {
    const values = line.split(',');
    const k = values.shift();
    mapping.mapping[k] = Array(headerIdx.length);
    headerIdx.forEach(i => {
      mapping.mapping[k][i] = values[i];
    });
  });
  return mapping;
}
796548
def make_format(self, fmt, width):
        
        if not self.report_data:
            return
        
        for data_item in self.report_data:
            if data_item.results:
                if fmt is None or fmt == 'text':
                    data_item.make_text(width)
                elif fmt == 'html':
                    data_item.make_html()
                elif fmt == 'csv':
                    data_item.make_csv()
1031422
def csvpretty(csvfile: csvfile=sys.stdin):
    
    shellish.tabulate(csv.reader(csvfile))
1314337
def parse_csv_dataset(data, handle_units):
    """"""
    fobj = BytesIO(data)
    names, units = parse_csv_header(fobj.readline().decode('utf-8'))
    arrs = np.genfromtxt(fobj, dtype=None, names=names, delimiter=',', unpack=True,
                         converters={'date': lambda s: parse_iso_date(s.decode('utf-8'))})
    d = {}
    for f in arrs.dtype.fields:
        dat = arrs[f]
        if dat.dtype == np.object:
            dat = dat.tolist()
        d[f] = handle_units(dat, units.get(f, None))
    return d
806576
def prepare(self, data):
        
        result = {}

        if not self.fields:
            # No fields specified. Serialize everything.
            return data

        for fieldname, lookup in self.fields.items():
            if isinstance(lookup, SubPreparer):
                result[fieldname] = lookup.prepare(data)
            else:
                result[fieldname] = self.lookup_data(lookup, data)

        return result