-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrang.py
More file actions
80 lines (72 loc) · 2.14 KB
/
wrang.py
File metadata and controls
80 lines (72 loc) · 2.14 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from wrangler import dw
import sys
if(len(sys.argv) < 3):
sys.exit('Error: Please include an input and output file. Example python script.py input.csv output.csv')
w = dw.DataWrangler()
# Split data repeatedly on newline into rows
w.add(dw.Split(column=["data"],
table=0,
status="active",
drop=True,
result="row",
update=False,
insert_position="right",
row=None,
on="\n",
before=None,
after=None,
ignore_between=None,
which=1,
max=0,
positions=None,
quote_character=None))
# Split data repeatedly on ','
w.add(dw.Split(column=["data"],
table=0,
status="active",
drop=True,
result="column",
update=False,
insert_position="right",
row=None,
on=",",
before=None,
after=None,
ignore_between=None,
which=1,
max=0,
positions=None,
quote_character=None))
# Delete rows where split2 = 'Discontinued'
w.add(dw.Filter(column=[],
table=0,
status="active",
drop=False,
row=dw.Row(column=[],
table=0,
status="active",
drop=False,
conditions=[dw.Eq(column=[],
table=0,
status="active",
drop=False,
lcol="split2",
value="Discontinued",
op_str="=")])))
# Delete rows where split5 = '0'
w.add(dw.Filter(column=[],
table=0,
status="active",
drop=False,
row=dw.Row(column=[],
table=0,
status="active",
drop=False,
conditions=[dw.Eq(column=[],
table=0,
status="active",
drop=False,
lcol="split5",
value="0",
op_str="=")])))
w.apply_to_file(sys.argv[1]).print_csv(sys.argv[2])