我有下表:
+----------------+---------+------------+
| Cambridge Data | IRR | Price List |
+================+=========+============+
| '3/31/1989' | '4.37%' | |
+----------------+---------+------------+
| '4/30/1989' | '5.35%' | |
+----------------+---------+------------+
我想转换表格并填充100
剑桥数据中日期为“1989 年 4 月 30 日”的价目表。我使用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
这是一个使用 petl 文档中类似方法的示例:
>>> # 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 |
+-----+-------+--------------------+