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
import csv
from itertools import izip
with open('source.csv') as f:
reader = csv.reader(f)
# filter data
data = (row for row in reader if row[1].strip() in ('5', '8'))
# make a new variable
data = (row + [int(row[2]) * 3] for row in data)
# transpose data
data = izip(*data)
# write data to a new csv file
with open('destination.csv', 'w') as fw:
csv.writer(fw).writerows(data)