forked from zygmuntz/phraug2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_cols.py
38 lines (28 loc) · 1 KB
/
delete_cols.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import csv
import sys
import argparse
parser = argparse.ArgumentParser(description='delete some columns from file, given by their indexes')
parser.add_argument("input_file", help = "path to csv input file")
parser.add_argument("output_file", help = "path to output file")
parser.add_argument('index', metavar='I', type=int, nargs='+',
help='an index or indexes to delete')
parser.add_argument("-v", "--verbose", help = "will write counts during process to standard out",
action = "store_true", default = False)
args = parser.parse_args()
args.index.sort( reverse = True )
if args.verbose:
print "%s ---> %s" % ( args.input_file, args.output_file )
print "header indices: %s" % ( args.index )
reader = csv.reader(open( args.input_file ))
writer = csv.writer(open( args.output_file, 'wb' ))
counter = 0
for line in reader:
#deal with empty line
if not line:
break
for h in args.index:
del line[h]
writer.writerow( line )
counter += 1
if counter % 10000 == 0 and args.verbose:
print counter