def get_relationships(self): "Parses a list of `Relationship` objects." core_file = _find_loinc_table_core_file(self.uri.path) core = etl.fromcsv(core_file, delimiter=',') core = etl.cut(core, ['LOINC_NUM', 'LONG_COMMON_NAME']) hierarchy_file = _find_multi_axial_hierarchy_file(self.uri.path) hierarchy = etl.fromcsv(hierarchy_file, delimiter=',') hierarchy = etl.leftjoin(hierarchy, core, lkey='CODE', rkey='LOINC_NUM') hierarchy = etl.cut(hierarchy, ['IMMEDIATE_PARENT', 'CODE', 'CODE_TEXT', 'LONG_COMMON_NAME']) hierarchy = etl.fillright(hierarchy) hierarchy = etl.cut(hierarchy, ['IMMEDIATE_PARENT', 'CODE', 'LONG_COMMON_NAME']) hierarchy = etl.rename(hierarchy, 'LONG_COMMON_NAME', 'CODE_TEXT') parents = etl.cut(hierarchy, ['CODE', 'CODE_TEXT']) hierarchy = etl.selectne(hierarchy, 'IMMEDIATE_PARENT', '') hierarchy = etl.leftjoin(hierarchy, parents, lkey='IMMEDIATE_PARENT', rkey='CODE', lprefix='source.', rprefix='target.') hierarchy = etl.distinct(hierarchy) if self.versioned: version = _parse_version(hierarchy_file) hierarchy = etl.addfield(hierarchy, 'version', version) hierarchy = etl.rowmapmany(hierarchy, _to_json, ['relationship']) return hierarchy
table4 = filldown(table1, 'bar', 'baz') look(table4) # fillright table1 = (('foo', 'bar', 'baz'), (1, 'a', None), (1, None, .23), (1, 'b', None), (2, None, None), (2, None, .56), (2, 'c', None), (None, 'c', .72)) from petl import fillright, look look(table1) table2 = fillright(table1) look(table2) # fillleft table1 = (('foo', 'bar', 'baz'), (1, 'a', None), (1, None, .23), (1, 'b', None), (2, None, None), (None, None, .56), (2, 'c', None), (None, 'c', .72)) from petl import fillleft, look look(table1) table2 = fillleft(table1) look(table2)
# fillright() ############# import petl as etl table1 = [ ["foo", "bar", "baz"], [1, "a", None], [1, None, 0.23], [1, "b", None], [2, None, None], [2, None, 0.56], [2, "c", None], [None, "c", 0.72], ] table2 = etl.fillright(table1) table2.lookall() # fillleft() ############ import petl as etl table1 = [ ["foo", "bar", "baz"], [1, "a", None], [1, None, 0.23], [1, "b", None], [2, None, None], [2, None, 0.56],
import petl as etl table1 = [['foo', 'bar', 'baz'], [1, 'a', None], [1, None, .23], [1, 'b', None], [2, None, None], [2, None, .56], [2, 'c', None], [None, 'c', .72]] table2 = etl.filldown(table1) table2.lookall() table3 = etl.filldown(table1, 'bar') table3.lookall() table4 = etl.filldown(table1, 'bar', 'baz') table4.lookall() # fillright() ############# import petl as etl table1 = [['foo', 'bar', 'baz'], [1, 'a', None], [1, None, .23], [1, 'b', None], [2, None, None], [2, None, .56], [2, 'c', None], [None, 'c', .72]] table2 = etl.fillright(table1) table2.lookall() # fillleft() ############ import petl as etl table1 = [['foo', 'bar', 'baz'], [1, 'a', None], [1, None, .23], [1, 'b', None], [2, None, None], [2, None, .56], [2, 'c', None], [None, 'c', .72]] table2 = etl.fillleft(table1) table2.lookall()