File: base.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 (114 lines) | stat: -rw-r--r-- 1,791 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
102
103
104
105
106
107
108
109
110
111
112
113
114
from __future__ import division, print_function, absolute_import, \
    unicode_literals


# values()
##########

import petl as etl
table1 = [['foo', 'bar'],
          ['a', True],
          ['b'],
          ['b', True],
          ['c', False]]
foo = etl.values(table1, 'foo')
foo
list(foo)
bar = etl.values(table1, 'bar')
bar
list(bar)
# values from multiple fields
table2 = [['foo', 'bar', 'baz'],
          [1, 'a', True],
          [2, 'bb', True],
          [3, 'd', False]]
foobaz = etl.values(table2, 'foo', 'baz')
foobaz
list(foobaz)


# header()
##########


import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
etl.header(table)


# fieldnames()
##############

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
etl.fieldnames(table)
etl.header(table)


# data()
########

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
d = etl.data(table)
list(d)


# dicts()
#########

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
d = etl.dicts(table)
d
list(d)


# namedtuples()
###############

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
d = etl.namedtuples(table)
d
list(d)


# records()
###############

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
d = etl.records(table)
d
list(d)


# rowgroupby()
##############

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          ['a', 1, True],
          ['b', 3, True],
          ['b', 2]]
# group entire rows
for key, group in etl.rowgroupby(table1, 'foo'):
    print(key, list(group))

# group specific values
for key, group in etl.rowgroupby(table1, 'foo', 'bar'):
    print(key, list(group))


# empty()
#########

import petl as etl
table = (
    etl
    .empty()
    .addcolumn('foo', ['A', 'B'])
    .addcolumn('bar', [1, 2])
)
table