In [1]:
import sys
sys.version_info
Out[1]:
sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)
In [2]:
import petl as etl
etl.__version__
Out[2]:
'1.1.0.dev0'
In [3]:
tbl = etl.dummytable(10, seed=42)
tbl
Out[3]:
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245

...

In [4]:
tbl.display(2)
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275

...

In [5]:
tbl.displayall()
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245
29 apples 0.561245062938613
91 oranges 0.2204406220406967
75 bananas 0.8094304566778266
0 pears 0.6981393949882269
43 bananas 0.15547949981178155
In [6]:
tbl.display()
tbl.display(index_header=True)
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245

...

0|foo 1|bar 2|baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245

...

In [7]:
tbl.display(caption='example data')
example data
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245

...

In [9]:
tbl.display(epilogue='example data')
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245

example data

In [10]:
tbl.display(truncate=4)
foo bar baz
81 appl 0.02
35 pear 0.22
94 appl 0.67
69 appl 0.59
4 appl 0.09

...

In [11]:
tbl.display(tr_style=lambda row: 'background-color: %s' % ('#faa' if row.foo > 50 else 'white'))
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245

...

In [12]:
tbl.display(tr_style='font-size: .8em',
            td_styles={'bar': 'background-color: yellow',
                       'baz': lambda v: 'background-color: %s' % ('#faa' if v > .5 else '#aaf')})
foo bar baz
81 apples 0.025010755222666936
35 pears 0.22321073814882275
94 apples 0.6766994874229113
69 apples 0.5904925124490397
4 apples 0.09369523986159245

...

In [13]:
t = ((u'name', u'id'),
     (u'Արամ Խաչատրյան', 1),
     (u'Johann Strauß', 2),
     (u'Вагиф Сәмәдоғлу', 3),
     (u'章子怡', 4),
     (u'Արամ Խաչատրյան', 1),
     (u'Johann Strauß', 2),
     (u'Вагиф Сәмәдоғлу', 3),
     (u'章子怡', 4))
t
Out[13]:
(('name', 'id'),
 ('Արամ Խաչատրյան', 1),
 ('Johann Strauß', 2),
 ('Вагиф Сәмәдоғлу', 3),
 ('章子怡', 4),
 ('Արամ Խաչատրյան', 1),
 ('Johann Strauß', 2),
 ('Вагиф Сәмәдоғлу', 3),
 ('章子怡', 4))
In [14]:
tbl2 = etl.wrap(t)
tbl2
Out[14]:
name id
Արամ Խաչատրյան 1
Johann Strauß 2
Вагиф Сәмәдоғлу 3
章子怡 4
Արամ Խաչատրյան 1

...

In [15]:
tbl2.display(caption='unicode example')
unicode example
name id
Արամ Խաչատրյան 1
Johann Strauß 2
Вагиф Сәмәдоғлу 3
章子怡 4
Արամ Խաչատրյան 1

...

In [13]: