File: numpy.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 (46 lines) | stat: -rw-r--r-- 947 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
from __future__ import division, print_function, absolute_import


# toarray()
###########

import petl as etl
table = [('foo', 'bar', 'baz'),
         ('apples', 1, 2.5),
         ('oranges', 3, 4.4),
         ('pears', 7, .1)]
a = etl.toarray(table)
a
# the dtype can be specified as a string
a = etl.toarray(table, dtype='a4, i2, f4')
a
# the dtype can also be partially specified
a = etl.toarray(table, dtype={'foo': 'a4'})
a


# fromarray()
#############

import petl as etl
import numpy as np
a = np.array([('apples', 1, 2.5),
              ('oranges', 3, 4.4),
              ('pears', 7, 0.1)],
             dtype='U8, i4,f4')
table = etl.fromarray(a)
table


# valuestoarray()
#################

import petl as etl
table = [('foo', 'bar', 'baz'),
         ('apples', 1, 2.5),
         ('oranges', 3, 4.4),
         ('pears', 7, .1)]
table = etl.wrap(table)
table.values('bar').array()
# specify dtype
table.values('bar').array(dtype='i4')