Friday, May 2, 2014

Looking for a simple way to add columns based on the other ones?

Are you looking for a simple way to add columns based on some other ones?
Let's say you want to add the column C where C=A+B?
you can do cat *.tsv | ./coladd.py -a C=A+B

if you do add more fields, separate your equations with ',' like this:
cat *.tsv | ./coladd.py -a C=A+B, D=(A/C)

eval() and csv.DictReader have been leveraged to achieve this task.
code: coladd.py