我有一个数据框,其中列出了一系列交易记录。我希望将exec_price字段与size字段相乘,以此计算出总成本。
因此,我需要添加一个新的字段:cost = exec_price * size。
date security action size ask_price exec_price \
order_id
188 2016-10-24 10:04:44 AAPL buy 5 116.599998 117.44
189 2016-10-24 10:04:44 NFLX buy 5 127.5 128.4
190 2016-10-24 10:04:44 AMD buy 5 6.52 6.65
status
order_id
188 filled
189 filled
190 filled
当我尝试使用以下代码进行乘法时:
transactions['cost'] = transactions['exec_price'] * transactions['size']
I get this:
date security action size ask_price exec_price \
order_id
188 2016-10-24 10:04:44 AAPL buy 5 116.599998 117.44
189 2016-10-24 10:04:44 NFLX buy 5 127.5 128.4
190 2016-10-24 10:04:44 AMD buy 5 6.52 6.65
status cost
order_id
188 filled 117.44117.44117.44117.44117.44
189 filled 128.4128.4128.4128.4128.4
190 filled 6.656.656.656.656.65
有人知道我该如何解决这个问题吗?
提前感谢。
astype
更改dtype,否则请使用内置的to_XXXX
方法,因为它们具有更好的错误处理。 - EdChum