示例#1
0
文件: examples.py 项目: datamade/petl

# mergeduplicates

table1 = [['foo', 'bar', 'baz'],
          ['A', 1, 2.7],
          ['B', 2, None],
          ['D', 3, 9.4],
          ['B', None, 7.8],
          ['E', None, 42.],
          ['D', 3, 12.3],
          ['A', 2, None]]

from petl import mergeduplicates, look    
look(table1)
table2 = mergeduplicates(table1, 'foo')
look(table2)


# merge

table1 = [['foo', 'bar', 'baz'],
          [1, 'A', True],
          [2, 'B', None],
          [4, 'C', True]]
table2 = [['bar', 'baz', 'quux'],
          ['A', True, 42.0],
          ['B', False, 79.3],
          ['C', False, 12.4]]

from petl import look, merge
示例#2
0
aggregation['sumbar'] = 'bar', sum
# default aggregation function is list
aggregation['listbar'] = 'bar'
aggregation['listbarbaz'] = ('bar', 'baz'), list
aggregation['bars'] = 'bar', etl.strjoin(', ')
table5 = etl.aggregate(table1, 'foo', aggregation)
table5

# mergeduplicates()
###################

import petl as etl

table1 = [['foo', 'bar', 'baz'], ['A', 1, 2.7], ['B', 2, None], ['D', 3, 9.4],
          ['B', None, 7.8], ['E', None, 42.], ['D', 3, 12.3], ['A', 2, None]]
table2 = etl.mergeduplicates(table1, 'foo')
table2

# merge()
#########

import petl as etl

table1 = [['foo', 'bar', 'baz'], [1, 'A', True], [2, 'B', None],
          [4, 'C', True]]
table2 = [['bar', 'baz', 'quux'], ['A', True, 42.0], ['B', False, 79.3],
          ['C', False, 12.4]]
table3 = etl.merge(table1, table2, key='bar')
table3

# fold()
示例#3
0

# mergeduplicates

table1 = [['foo', 'bar', 'baz'],
          ['A', 1, 2.7],
          ['B', 2, None],
          ['D', 3, 9.4],
          ['B', None, 7.8],
          ['E', None, 42.],
          ['D', 3, 12.3],
          ['A', 2, None]]

from petl import mergeduplicates, look    
look(table1)
table2 = mergeduplicates(table1, 'foo')
look(table2)


# merge

table1 = [['foo', 'bar', 'baz'],
          [1, 'A', True],
          [2, 'B', None],
          [4, 'C', True]]
table2 = [['bar', 'baz', 'quux'],
          ['A', True, 42.0],
          ['B', False, 79.3],
          ['C', False, 12.4]]

from petl import look, merge
示例#4
0
table5


# mergeduplicates()
###################

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          ['A', 1, 2.7],
          ['B', 2, None],
          ['D', 3, 9.4],
          ['B', None, 7.8],
          ['E', None, 42.],
          ['D', 3, 12.3],
          ['A', 2, None]]
table2 = etl.mergeduplicates(table1, 'foo')
table2


# merge()
#########

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          [1, 'A', True],
          [2, 'B', None],
          [4, 'C', True]]
table2 = [['bar', 'baz', 'quux'],
          ['A', True, 42.0],
          ['B', False, 79.3],
          ['C', False, 12.4]]