Convert from CSV, first handling header row specially.
170634
def load_csv(vs):
    ''
    with vs.source.open_text() as fp:
        for i in range(options.skip):
            wrappedNext(fp)  # discard initial lines

        if options.safety_first:
            rdr = csv.reader(removeNulls(fp), **csvoptions())
        else:
            rdr = csv.reader(fp, **csvoptions())

        vs.rows = []

        # headers first, to setup columns before adding rows
        headers = [wrappedNext(rdr) for i in range(int(options.header))]

        if headers:
            # columns ideally reflect the max number of fields over all rows
            vs.columns = ArrayNamedColumns('\\n'.join(x) for x in zip(*headers))
        else:
            r = wrappedNext(rdr)
            vs.addRow(r)
            vs.columns = ArrayColumns(len(vs.rows[0]))

        if not vs.columns:
            vs.columns = [ColumnItem(0)]

        vs.recalc()  # make columns usable
        with Progress(total=vs.source.filesize) as prog:
            try:
                samplelen = 0
                for i in range(options_num_first_rows):  # for progress below
                    row = wrappedNext(rdr)
                    vs.addRow(row)
                    samplelen += sum(len(x) for x in row)

                samplelen //= options_num_first_rows  # avg len of first n rows

                while True:
                    vs.addRow(wrappedNext(rdr))
                    prog.addProgress(samplelen)
            except StopIteration:
                pass  # as expected

    vs.recalc()
    return vs
1316021
def _dump_csv(self, rows):
        
        self.logger.debug('Writing %r', rows)
        csv = self._maybe_import('csv')
        buff = io.StringIO() if _PYTHON3 else io.BytesIO()
        writer = csv.DictWriter(
            buff,
            sorted(set([k for r in rows for k in r.keys()])),
            dialect='excel')
        writer.writeheader()
        writer.writerows(rows)
        value = buff.getvalue()
        buff.close()
        return value
871849
public static RowMajorSparseMatrix fromCSV(String csv) {
        return Matrix.fromCSV(csv).to(Matrices.SPARSE_ROW_MAJOR);
    }
1199608
protected function fetchCSVHeader()
    {
        $srcRow = fgetcsv(
            $this->fileHandle,
            0,
            $this->delimiter,
            $this->enclosure
        );

        $this->headerRow = $this->remapHeader($srcRow);
    }
1022680
public function loadCSV()
    {
        $parser = new CSVParser($this->file);
        $count = 0;
        foreach ($parser as $row) {
            $this->rows[]= $row;
            $count++;
            if ($count == $this->previewcount) {
                break;
            }
        }
        $firstrow = array_keys($this->rows[0]);

        //hack to include first row as a
        array_unshift($this->rows, array_combine($firstrow, $firstrow));

        if (count($this->rows) > 0) {
            $this->headings = $firstrow;
        }
    }
399451
def parse_csv_response(data, unit_handler):
    """"""
    return squish([parse_csv_dataset(d, unit_handler) for d in data.split(b'\n\n')])
278127
def parse_csv(self, infile, delimiter=",", decimal_sep="."):
        ""
        keys = ('name','type','x1','y1','x2','y2','font','size',
            'bold','italic','underline','foreground','background',
            'align','text','priority', 'multiline')
        self.elements = []
        self.pg_no = 0
        if not PY3K:
            f = open(infile, 'rb')
        else:
            f = open(infile)
        for row in csv.reader(f, delimiter=delimiter):
            kargs = {}
            for i,v in enumerate(row):
                if not v.startswith("'") and decimal_sep!=".": 
                    v = v.replace(decimal_sep,".")
                else:
                    v = v
                if v=='':
                    v = None
                else:
                    v = eval(v.strip())
                kargs[keys[i]] = v
            self.elements.append(kargs)
        self.keys = [v['name'].lower() for v in self.elements]
39790
def read_csv(filename, keys=None, convert_types=False, **kwargs):
    '''
    

    '''
    df = pd.read_csv(filename)
    if convert_types:
        df = convert_types_slow(df)
    if keys:
        df = df[df['key'].isin(keys)]
    df = process_one(df)
    return df
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))
326775
def read_csv(filename):
    

    with open(filename, 'r') as f:
        r = csv.reader(f)
        next(r)  # remove header
        wm = list(r)

    # remove header and convert to numeric
    for i, row in enumerate(wm):
        row[1:4] = map(int, row[1:4])
        row[4] = float(row[4])

    return wm
345603
def parse_csv_header(line):
    """"""
    units = {}
    names = []
    for var in line.split(','):
        start = var.find('[')
        if start < 0:
            names.append(str(var))
            continue
        else:
            names.append(str(var[:start]))
        end = var.find(']', start)
        unitstr = var[start + 1:end]
        eq = unitstr.find('=')
        if eq >= 0:
            # go past = and ", skip final "
            units[names[-1]] = unitstr[eq + 2:-1]
    return names, units
84969
def get_header_values(self):
        
        lines = self.getOriginalFile().data.splitlines()
        reader = csv.reader(lines)
        header_fields = header_data = []
        for row in reader:
            if not any(row):
                continue
            if row[0].strip().lower() == 'header':
                header_fields = [x.strip() for x in row][1:]
                continue
            if row[0].strip().lower() == 'header data':
                header_data = [x.strip() for x in row][1:]
                break
        if not (header_data or header_fields):
            return None
        if not (header_data and header_fields):
            self.error("File is missing header row or header data")
            return None
        # inject us out of here
        values = dict(zip(header_fields, header_data))
        # blank cell from sheet will probably make it in here:
        if '' in values:
            del (values[''])
        return values
1218158
public static BasicVector fromCSV(String csv) {
        return Vector.fromCSV(csv).to(Vectors.BASIC);
    }
526057
def csv_to_dict(csv_filepath, **kwargs):
    
    callbacks = {'to_list': csv_tolist,
                 'row_csv_limiter': row_csv_limiter,
                 'csv_row_cleaner': csv_row_cleaner,
                 'row_headers_count': row_headers_count,
                 'get_col_header': get_csv_col_headers,
                 'get_row_headers': get_row_headers,
                 'populate_headers': populate_headers,
                 'csv_column_header_cleaner': csv_column_header_cleaner,
                 'csv_column_cleaner': csv_column_cleaner,
                 'retrieve_csv_data': retrieve_csv_data}

    callbacks.update(kwargs.get('alt_callbacks', {}))
    rows = kwargs.get('rows', [])

    if not rows:
        # csv_tolist of rows
        rows = callbacks.get('to_list')(csv_filepath, **kwargs)

        if not rows:
            msg = 'Empty rows obtained from {}'.format(csv_filepath)
            logger.warning(msg)
            raise ValueError(msg)

    # apply limits
    rows = callbacks.get('row_csv_limiter')(
        rows, kwargs.get('limits', [None, None]))

    # apply row cleaner
    rows = callbacks.get('csv_row_cleaner')(rows)

    # apply column cleaner
    rows = callbacks.get('csv_column_cleaner')(rows)

    # count raw headers
    num_row_headers = callbacks.get('row_headers_count')(rows)

    # take colum_headers
    c_headers_raw = callbacks.get('get_col_header')(rows, num_row_headers)

    # get row_headers
    r_headers = callbacks.get('get_row_headers')(
        rows, num_row_headers, len(c_headers_raw))

    # format colum_headers
    c_headers_dirty = callbacks.get('populate_headers')(
        c_headers_raw) if len(c_headers_raw) > 1 else c_headers_raw[0]

    # Clean csv column headers of empty values.
    c_headers = callbacks.get('csv_column_header_cleaner')(c_headers_dirty)

    # take data
    csv_data = callbacks.get('retrieve_csv_data')(
        rows,
        column_header=len(c_headers_raw),
        row_header=num_row_headers,
        limit_column=len(c_headers) - len(c_headers_dirty) or None)

    # Check column headers validation
    if csv_data:
        assert len(c_headers) == len(csv_data[0])

    # Check row headers validation
    if r_headers:
        assert len(r_headers) == len(csv_data)

    # Transform rows into dict zipping the headers.
    kwargs.pop('rows', None)
    result = csv_format(csv_data, c_headers, r_headers, rows, **kwargs)

    return result
567900
def csv_dict_format(csv_data, c_headers=None, r_headers=None):
    
    # format dict if has row_headers
    if r_headers:
        result = {}
        for k_index in range(0, len(csv_data)):
            if r_headers[k_index]:
                result[r_headers[k_index]] = collections.OrderedDict(
                    zip(c_headers, csv_data[k_index]))

    # format list if hasn't row_headers -- square csv
    else:
        result = []
        for k_index in range(0, len(csv_data)):
            result.append(
                collections.OrderedDict(zip(c_headers, csv_data[k_index])))
        result = [result]

    return result
649594
public static Matrix fromCSV(String csv) {
        StringTokenizer lines = new StringTokenizer(csv, "\n");
        Matrix result = DenseMatrix.zero(10, 10);
        int rows = 0;
        int columns = 0;

        while (lines.hasMoreTokens()) {
            if (result.rows() == rows) {
                result = result.copyOfRows((rows * 3) / 2 + 1);
            }

            StringTokenizer elements = new StringTokenizer(lines.nextToken(), ", ");
            int j = 0;
            while (elements.hasMoreElements()) {
                if (j == result.columns()) {
                    result = result.copyOfColumns((j * 3) / 2 + 1);
                }

                double x = Double.parseDouble(elements.nextToken());
                result.set(rows, j++, x);
            }

            rows++;
            columns = j > columns ? j : columns;
        }

        return result.copyOfShape(rows, columns);
    }
921127
def get_row_headers(rows, row_headers_count_value=0, column_headers_count=1):
    
    # TODO: REFACTOR ALGORITHM NEEDED
    partial_headers = []

    if row_headers_count_value:

        # Take partial data
        for k_index in range(0, len(rows) - column_headers_count):
            header = rows[k_index + column_headers_count][
                :row_headers_count_value]
            partial_headers.append(remove_list_duplicates(force_list(header)))

        # Populate headers
        populated_headers = populate_csv_headers(
            rows,
            partial_headers,
            column_headers_count)

        return populated_headers