Writes columns of data to a target CSV file.

    :param dict d: A dictionary containing one list for every data column. Keys: int, Values: list
    :return None:
196609
def write_csv_to_file(d):
    
    logger_csvs.info("enter write_csv_to_file")

    try:
        for filename, data in d.items():
            try:
                l_columns = _reorder_csv(data, filename)
                rows = zip(*l_columns)
                with open(filename, 'w+') as f:
                    w = csv.writer(f)
                    for row in rows:
                        row2 = decimal_precision(row)
                        w.writerow(row2)
            except TypeError as e:
                print("Error: Unable to write values to CSV file, {}:\n"
                      "(1) The data table may have 2 or more identical variables. Please correct the LiPD file manually\n"
                      "(2) There may have been an error trying to prep the values for file write. The 'number' field in the data columns may be a 'string' instead of an 'integer' data type".format(filename))
                print(e)
            except Exception as e:
                print("Error: CSV file not written, {}, {}:\n"
                      "The data table may have 2 or more identical variables. Please correct the LiPD file manually".format(filename, e))
    except AttributeError as e:
        logger_csvs.error("write_csv_to_file: Unable to write CSV File: {}".format(e, exc_info=True))
    logger_csvs.info("exit write_csv_to_file")
    return
115792
def cast_values_csvs(d, idx, x):
    
    try:
        d[idx].append(float(x))
    except ValueError:
        d[idx].append(x)
        # logger_misc.warn("cast_values_csv: ValueError")
        # logger_misc.warn("ValueError: col: {}, {}".format(x, e))
    except KeyError as e:
        logger_misc.warn("cast_values_csv: KeyError: col: {}, {}".format(x, e))

    return d
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
403986
def _write_dict(self, val, outstream):
        '''
        
        '''
        fields = val.keys()
        length = len(fields)
        self.write_dict_start(length, outstream)
        if length > 0:
            self.write_dict_field(fields[0], val[fields[0]], outstream)
            idx = 1
            while idx < length:
                name = fields[idx]
                value = val[fields[idx]]
                self.write_dict_field_separator(name, value, outstream)
                self.write_dict_field(name, value, outstream)
                idx += 1
        self.write_dict_end(length, outstream)
976603
def write_table(self, d):
        
        # HACK: encoding of AMQP tables is broken because it requires the
        # length of the /encoded/ data instead of the number of items. To
        # support streaming, fiddle with cursor position, rewinding to write
        # the real length of the data. Generally speaking, I'm not a fan of
        # the AMQP encoding scheme, it could be much faster.
        table_len_pos = len(self._output_buffer)
        self.write_long(0)
        table_data_pos = len(self._output_buffer)

        for key, value in d.iteritems():
            self._write_item(key, value)

        table_end_pos = len(self._output_buffer)
        table_len = table_end_pos - table_data_pos

        self.write_long_at(table_len, table_len_pos)
        return self
426787
def dataframe(df, **kwargs):
    
    table(df.values, list(df.columns), **kwargs)
214615
def write_table(self, d):
        
        self._flushbits()
        table_data = AMQPWriter()
        for k, v in d.items():
            table_data.write_shortstr(k)
            if isinstance(v, basestring):
                if isinstance(v, unicode):
                    v = v.encode('utf-8')
                table_data.write(byte(83)) # 'S'
                table_data.write_longstr(v)
            elif isinstance(v, (int, long)):
                table_data.write(byte(73)) # 'I'
                table_data.write(pack('>i', v))
            elif isinstance(v, Decimal):
                table_data.write(byte(68)) # 'D'
                sign, digits, exponent = v.as_tuple()
                v = 0
                for d in digits:
                    v = (v * 10) + d
                if sign:
                    v = -v
                table_data.write_octet(-exponent)
                table_data.write(pack('>i', v))
            elif isinstance(v, datetime):
                table_data.write(byte(84)) # 'T'
                table_data.write_timestamp(v)
                ## FIXME: timezone ?
            elif isinstance(v, dict):
                table_data.write(byte(70)) # 'F'
                table_data.write_table(v)
            else:
                raise ValueError('%s not serializable in AMQP' % repr(v))
        table_data = table_data.getvalue()
        self.write_long(len(table_data))
        self.out.write(table_data)
103980
def write_table(self, d):
        """"""
        self._flushbits()
        table_data = AMQPWriter()
        for k, v in items(d):
            table_data.write_shortstr(k)
            table_data.write_item(v, k)
        table_data = table_data.getvalue()
        self.write_long(len(table_data))
        self.out.write(table_data)
536684
def _write_csv(filepath, data, kwargs):
    """"""
    kwargs_open = {'newline': ''}
    mode = 'w'
    if sys.version_info < (3, 0):
        kwargs_open.pop('newline', None)
        mode = 'wb'
    with open(filepath, mode, **kwargs_open) as fp:
        if 'delimiter' not in kwargs:
            kwargs['delimiter'] = ','
        if 'quotechar' not in kwargs:
            kwargs['quotechar'] = '"'
        with open(filepath, 'w') as fp:
            writer = csv.writer(fp, **kwargs)
            writer.writerows(data)
    return data
282257
def write(self, learn:Learner, trn_batch:Tuple, val_batch:Tuple, iteration:int, tbwriter:SummaryWriter)->None:
        ""
        self._write_for_dstype(learn=learn, batch=val_batch, iteration=iteration, tbwriter=tbwriter, ds_type=DatasetType.Valid)
        self._write_for_dstype(learn=learn, batch=trn_batch, iteration=iteration, tbwriter=tbwriter, ds_type=DatasetType.Train)
845670
def write(file_name, rows, header=None, *args, **kwargs):
        '''  '''
        warnings.warn("chirptext.io.CSV is deprecated and will be removed in near future.", DeprecationWarning)
        write_csv(file_name, rows, fieldnames=header, *args, **kwargs)
330756
def writeData(f, data):
    
    if not isinstance(data, dict):
      raise Exception(PyVDF.__ERR_NotDict.format(repr(data)))
    data = PyVDF.formatData(data)
    try:
      f.write(data)
    except AttributeError:
      pass

    try:
      filec = open(f, 'w')
      filec.write(data)
      filec.close()
    except IOError as e:
      print("Could not open '" + f + "' for writing.")
      print(e)
816503
def docify(self, df):
        
        dtypes = {}
        masks = {}
        lengths = {}
        columns = []
        data = Binary(b'')
        start = 0

        arrays = []
        for c in df:
            try:
                columns.append(str(c))
                arr, mask = self._convert_types(df[c].values)
                dtypes[str(c)] = arr.dtype.str
                if mask is not None:
                    masks[str(c)] = Binary(compress(mask.tostring()))
                arrays.append(arr.tostring())
            except Exception as e:
                typ = infer_dtype(df[c], skipna=False)
                msg = "Column '{}' type is {}".format(str(c), typ)
                logging.info(msg)
                raise e

        arrays = compress_array(arrays)
        for index, c in enumerate(df):
            d = Binary(arrays[index])
            lengths[str(c)] = (start, start + len(d) - 1)
            start += len(d)
            data += d

        doc = SON({DATA: data, METADATA: {}})
        doc[METADATA] = {COLUMNS: columns,
                         MASK: masks,
                         LENGTHS: lengths,
                         DTYPE: dtypes
                         }

        return doc
1012969
def write_csv(path, data):
    """"""

    fd = _try_open_file(path, 'w',
                        'The first argument must be a pathname or an object that supports write() method')
    for v in data:
        fd.write(",".join([str(x) for x in v]))
        fd.write("\n")
    _try_close_file(fd, path)
1043742
def write_dataframe(self, result, dst_paths, nodata=None, compress='lzw'):
        """"""
        result = self._convert_to_ndarray(result)
        self.write_ndarray(result, dst_paths, nodata=nodata, compress=compress)
782171
def write(self, data, method='w'):
        
        # Create list of lists from flat list
        data = data if isinstance(data[0], (list, set, tuple)) else [[d] for d in data]

        # Open file and write rows
        with open(self.file_path, method) as write:
            wr = csv_builtin.writer(write)
            wr.writerows(data)
        return self.file_path
290085
def append_data(self, attribute, values):
        """"""
        found = False
        if type(values) != list:
            values = [values]
        for col in self.Table:
            if attribute in col:
                dict_values = [u"{0}".format(value) for value in values]
                col[attribute] += dict_values
                found = True
        if not found:
            raise KeyError(attribute)