G
George Sakkis
csvutils is a single Python module for easily transforming csv (or csv-
like) generated rows. The release is available at http://pypi.python.org/pypi/csvutils/0.1.
Regards,
George
What is csvutils?
------------------------
The standard csv module is very useful for parsing tabular data in CSV
format. Typically though, one or more transformations need to be
applied to the generated rows before being ready to be used; for
instance "convert the 3rd column to int, the 5th to float and ignore
all the rest". csvutils provides an easy way to specify such
transformations upfront instead of coding them every time by hand.
Here are a few examples (more included as doctests):
... "0,-1.1,3.4,None"])) ... print row
[1, 3.3399999999999999]
[4, 4.0]
[0, -1.1000000000000001] ... print row
['1', 3.3399999999999999, '4-3.2j', 'John']
['4', 4.0, '4', '4']
['0', -1.1000000000000001, '3.4', 'None']
... print row
[1, 3.3399999999999999, (4-3.2000000000000002j)]
[4, 4, 4]
[0, -1.1000000000000001, 3.3999999999999999]
like) generated rows. The release is available at http://pypi.python.org/pypi/csvutils/0.1.
Regards,
George
What is csvutils?
------------------------
The standard csv module is very useful for parsing tabular data in CSV
format. Typically though, one or more transformations need to be
applied to the generated rows before being ready to be used; for
instance "convert the 3rd column to int, the 5th to float and ignore
all the rest". csvutils provides an easy way to specify such
transformations upfront instead of coding them every time by hand.
Here are a few examples (more included as doctests):
... "4,4,4,4",>>> import csv
>>> from csvutils import SequenceTransformer
>>> rows = list(csv.reader(["1,3.34,4-3.2j,John",
... "0,-1.1,3.4,None"])) ... print row
[1, 3.3399999999999999]
[4, 4.0]
[0, -1.1000000000000001] ... print row
['1', 3.3399999999999999, '4-3.2j', 'John']
['4', 4.0, '4', '4']
['0', -1.1000000000000001, '3.4', 'None']
(rows):>>> # exclude the 4th column and eval() the rest (XXX: Use eval for trusted data only)
>>> for row in SequenceTransformer(default=eval, exclude=[3])
... print row
[1, 3.3399999999999999, (4-3.2000000000000002j)]
[4, 4, 4]
[0, -1.1000000000000001, 3.3999999999999999]