I have the following table:
+----------------+---------+------------+
| Cambridge Data | IRR | Price List |
+================+=========+============+
| '3/31/1989' | '4.37%' | |
+----------------+---------+------------+
| '4/30/1989' | '5.35%' | |
+----------------+---------+------------+
I want to convert the table and populate a Price List of 100
when the date in Cambridge Data is '4/30/1989'. I have the following function using petl:
# Add an initial price to base calculations for Price List
def insert_initial_price(self, table):
table = etl.convert(table, 'Price List', lambda v, row: v = '100' if row['Cambridge Parser'] == '3/31/1989', pass_row=True)
return table
Here's an example using a similar method from petl's documentation:
>>> # conversion can access other values from the same row
... table12 = etl.convert(table1, 'baz',
... lambda v, row: v * float(row.bar),
... pass_row=True)
>>> table12
+-----+-------+--------------------+
| foo | bar | baz |
+=====+=======+====================+
| 'A' | '2.4' | 28.799999999999997 |
+-----+-------+--------------------+
| 'B' | '5.7' | 193.8 |
+-----+-------+--------------------+
| 'C' | '1.2' | 67.2 |
+-----+-------+--------------------+