Пример #1
0
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))

from petl import intersection, look
look(table1)
look(table2)
table3 = intersection(table1, table2)
look(table3)


# pivot

table1 = (('region', 'gender', 'style', 'units'),
          ('east', 'boy', 'tee', 12),
          ('east', 'boy', 'golf', 14),
          ('east', 'boy', 'fancy', 7),
          ('east', 'girl', 'tee', 3),
          ('east', 'girl', 'golf', 8),
          ('east', 'girl', 'fancy', 18),
          ('west', 'boy', 'tee', 12),
          ('west', 'boy', 'golf', 15),
          ('west', 'boy', 'fancy', 8),
Пример #2
0
     ['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