File: setops.py

package info (click to toggle)
python-petl 1.7.17-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,224 kB
  • sloc: python: 22,617; makefile: 109; xml: 9
file content (101 lines) | stat: -rw-r--r-- 1,872 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from __future__ import absolute_import, print_function, division


# complement()
##############

import petl as etl
a = [['foo', 'bar', 'baz'],
     ['A', 1, True],
     ['C', 7, False],
     ['B', 2, False],
     ['C', 9, True]]
b = [['x', 'y', 'z'],
     ['B', 2, False],
     ['A', 9, False],
     ['B', 3, True],
     ['C', 9, True]]
aminusb = etl.complement(a, b)
aminusb
bminusa = etl.complement(b, a)
bminusa


# recordcomplement()
####################

import petl as etl
a = [['foo', 'bar', 'baz'],
     ['A', 1, True],
     ['C', 7, False],
     ['B', 2, False],
     ['C', 9, True]]
b = [['bar', 'foo', 'baz'],
     [2, 'B', False],
     [9, 'A', False],
     [3, 'B', True],
     [9, 'C', True]]
aminusb = etl.recordcomplement(a, b)
aminusb
bminusa = etl.recordcomplement(b, a)
bminusa


# diff()
########

import petl as etl
a = [['foo', 'bar', 'baz'],
     ['A', 1, True],
     ['C', 7, False],
     ['B', 2, False],
     ['C', 9, True]]
b = [['x', 'y', 'z'],
     ['B', 2, False],
     ['A', 9, False],
     ['B', 3, True],
     ['C', 9, True]]
added, subtracted = etl.diff(a, b)
# rows in b not in a
added
# rows in a not in b
subtracted


# recorddiff()
##############

import petl as etl
a = [['foo', 'bar', 'baz'],
     ['A', 1, True],
     ['C', 7, False],
     ['B', 2, False],
     ['C', 9, True]]
b = [['bar', 'foo', 'baz'],
     [2, 'B', False],
     [9, 'A', False],
     [3, 'B', True],
     [9, 'C', True]]
added, subtracted = etl.recorddiff(a, b)
added
subtracted


# intersection()
################

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          ['A', 1, True],
          ['C', 7, False],
          ['B', 2, False],
          ['C', 9, True]]
table2 = [['x', 'y', 'z'],
          ['B', 2, False],
          ['A', 9, False],
          ['B', 3, True],
          ['C', 9, True]]
table3 = etl.intersection(table1, table2)
table3