I have been working with R for several years. R is very strong in data manipulation. I\'m learning python and I would like to know how to manipulate data using python. Basically
There's a module for CSV parsing in the standard library. To get a list of row each containing a list of the cells, you can use list(csv.reader(...))
.
Step 2 and 3 can be written in one list comprehension: [(var1, var2, var3, var3 * 3) for var1, var2, var3 in data if var2 in ('5', '8')]
.
I'm not aware of anything in the standard library for transposing lists of lists. Perhaps NumPy or SciPy has something. A quick and dirty way would be zipping the rows (zip(*lists)
).
Writing back to file should be as simple as constructing as csv.writer
and passing it each row in a loop.