

def fieldmap(table, mappings=None, failonerror=False, errorvalue=None):
    "\n    Transform a table, mapping fields arbitrarily between input and output.\n    E.g.::\n\n        >>> import petl as etl\n        >>> from collections import OrderedDict\n        >>> table1 = [['id', 'sex', 'age', 'height', 'weight'],\n        ...           [1, 'male', 16, 1.45, 62.0],\n        ...           [2, 'female', 19, 1.34, 55.4],\n        ...           [3, 'female', 17, 1.78, 74.4],\n        ...           [4, 'male', 21, 1.33, 45.2],\n        ...           [5, '-', 25, 1.65, 51.9]]\n        >>> mappings = OrderedDict()\n        >>> # rename a field\n        ... mappings['subject_id'] = 'id'\n        >>> # translate a field\n        ... mappings['gender'] = 'sex', {'male': 'M', 'female': 'F'}\n        >>> # apply a calculation to a field\n        ... mappings['age_months'] = 'age', lambda v: v * 12\n        >>> # apply a calculation to a combination of fields\n        ... mappings['bmi'] = lambda rec: rec['weight'] / rec['height']**2\n        >>> # transform and inspect the output\n        ... table2 = etl.fieldmap(table1, mappings)\n        >>> table2\n        +------------+--------+------------+--------------------+\n        | subject_id | gender | age_months | bmi                |\n        +============+========+============+====================+\n        |          1 | 'M'    |        192 |  29.48870392390012 |\n        +------------+--------+------------+--------------------+\n        |          2 | 'F'    |        228 |   30.8531967030519 |\n        +------------+--------+------------+--------------------+\n        |          3 | 'F'    |        204 | 23.481883600555488 |\n        +------------+--------+------------+--------------------+\n        |          4 | 'M'    |        252 |  25.55260331279326 |\n        +------------+--------+------------+--------------------+\n        |          5 | '-'    |        300 |   19.0633608815427 |\n        +------------+--------+------------+--------------------+\n\n    Note also that the mapping value can be an expression string, which will be\n    converted to a lambda function via :func:`petl.util.base.expr`.\n\n    "
    return FieldMapView(table, mappings=errorvalue, failonerror=failonerror, errorvalue=errorvalue)

dataset/ETHPy150Open alimanfoo/petl/petl/transform/maps.py fieldmap/VarMisuse@31/779 `mappings`->`errorvalue`