File: regex.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 (68 lines) | stat: -rw-r--r-- 1,670 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
from __future__ import absolute_import, print_function, division


# capture()
############

import petl as etl
table1 = [['id', 'variable', 'value'],
          ['1', 'A1', '12'],
          ['2', 'A2', '15'],
          ['3', 'B1', '18'],
          ['4', 'C12', '19']]
table2 = etl.capture(table1, 'variable', '(\\w)(\\d+)',
                     ['treat', 'time'])
table2
# using the include_original argument
table3 = etl.capture(table1, 'variable', '(\\w)(\\d+)',
                     ['treat', 'time'],
                     include_original=True)
table3


# split()
#########

import petl as etl
table1 = [['id', 'variable', 'value'],
          ['1', 'parad1', '12'],
          ['2', 'parad2', '15'],
          ['3', 'tempd1', '18'],
          ['4', 'tempd2', '19']]
table2 = etl.split(table1, 'variable', 'd', ['variable', 'day'])
table2


# search()
##########

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          ['orange', 12, 'oranges are nice fruit'],
          ['mango', 42, 'I like them'],
          ['banana', 74, 'lovely too'],
          ['cucumber', 41, 'better than mango']]
# search any field
table2 = etl.search(table1, '.g.')
table2
# search a specific field
table3 = etl.search(table1, 'foo', '.g.')
table3


# searchcomplement()
####################

import petl as etl
table1 = [['foo', 'bar', 'baz'],
          ['orange', 12, 'oranges are nice fruit'],
          ['mango', 42, 'I like them'],
          ['banana', 74, 'lovely too'],
          ['cucumber', 41, 'better than mango']]
# search any field
table2 = etl.searchcomplement(table1, '.g.')
table2
# search a specific field
table3 = etl.searchcomplement(table1, 'foo', '.g.')
table3