CSV.py - Tools for parsing CSV files

Author:Andreas Heger
Release:$Id$
Date:December 09, 2013
Tags:Python
CSV.ConvertDictionary(d, map={})

tries to convert values in a dictionary.

if map contains ‘default’, a default conversion is enforced. For example, to force int for every column but column id, supply map = {‘default’ : “int”, “id” : “str” }

CSV.GetMapColumn2Type(rows, ignore_empty=False, get_max_values=False)

map fields to types based on rows.

Preference is Int to Float to String.

If get_max_values is set to true, the maximum values for integer columns are returned in a dictionary.

class CSV.CommentStripper(infile)

iterator class for stripping comments from file.

class CSV.DictReader(infile, *args, **kwargs)

Bases: csv.DictReader

like csv.DictReader, but skip comments (lines starting with “#”).

class CSV.DictReaderLarge(infile, fieldnames, *args, **kwargs)

drop-in for csv.DictReader - handles very large fields

Warning - minimal implementation - does not handle dialects

CSV.ReadTable(lines, as_rows=True, with_header=True, ignore_incomplete=False, dialect='excel-tab')

read a table from infile

returns table as rows or as columns. If remove_incomplete, incomplete rows are simply ignored.

CSV.ReadTables(infile, *args, **kwargs)

read a set of csv tables.

Individual tables are separated by // on a single line.

CSV.GroupTable(table, group_column=0, group_function=<built-in function min>, missing_value='na')

group table by group_column.

The table need not be sorted.

Previous topic

Experiment.py - Tools for scripts

Next topic

IOTools - tools for I/O operations

This Page