table1 = [['lines',], ['A',], [1,], [True,], ['C',], [7,], [False,], ['B',], [2,], [False,], ['C'], [9,]] from petl import unflatten, look input = ['A', 1, True, 'C', 7, False, 'B', 2, False, 'C', 9] table = unflatten(input, 3) look(table) # a table and field name can also be provided as arguments look(table1) table2 = unflatten(table1, 'lines', 3) look(table2) # tocsv table = [['foo', 'bar'], ['a', 1], ['b', 2], ['c', 2]] from petl import tocsv, look
] table2 = etl.pivot(table1, "region", "gender", "units", sum) table2 table3 = etl.pivot(table1, "region", "style", "units", sum) table3 table4 = etl.pivot(table1, "gender", "style", "units", sum) table4 # flatten() ########### import petl as etl table1 = [["foo", "bar", "baz"], ["A", 1, True], ["C", 7, False], ["B", 2, False], ["C", 9, True]] list(etl.flatten(table1)) # unflatten() ############# import petl as etl a = ["A", 1, True, "C", 7, False, "B", 2, False, "C", 9] table1 = etl.unflatten(a, 3) table1 # a table and field name can also be provided as arguments table2 = [["lines"], ["A"], [1], [True], ["C"], [7], [False], ["B"], [2], [False], ["C"], [9]] table3 = etl.unflatten(table2, "lines", 3) table3
import pandas as pd import numpy as np import petl as pt from petl import filldown, fillright, fillleft, look from petl import unflatten input = ['A', 3, True, None, 7, False, 'B', 2, False, 'C', 9] table = unflatten(input, 3) print(table) a = filldown(table) print(a)
import petl as etl table1 = [['foo', 'bar', 'baz'], ['A', 1, True], ['C', 7, False], ['B', 2, False], ['C', 9, True]] list(etl.flatten(table1)) # unflatten() ############# import petl as etl a = ['A', 1, True, 'C', 7, False, 'B', 2, False, 'C', 9] table1 = etl.unflatten(a, 3) table1 # a table and field name can also be provided as arguments table2 = [['lines'], ['A'], [1], [True], ['C'], [7], [False], ['B'], [2], [False], ['C'], [9]] table3 = etl.unflatten(table2, 'lines', 3)