如何使用pandas / python将DataFrame系列从价格更改为百分比

时间:2016-05-31 12:29:33

标签: python python-3.x pandas

我有一个pandas dataFrame,日期,时间和股票价格如下:

+------------+-------+-------+-------+
|            | 08:01 | 08:02 | 08:03 |
+------------+-------+-------+-------+
| 01/01/2016 | 50    | 50.5  | 50.7  |
+------------+-------+-------+-------+
| 02/01/2016 | 49.6  | 49.5  | 49.6  |
+------------+-------+-------+-------+

现在我想将价格更改为当天的价格变化。第一个价格总是0%。看起来应该是这样的:

+------------+-------+--------+-------+
|            | 08:01 | 08:02  | 08:03 |
+------------+-------+--------+-------+
| 01/01/2016 | 0     | 0.01   | 0.014 |
+------------+-------+--------+-------+
| 02/01/2016 | 0     | -0.002 | 0     |
+------------+-------+--------+-------+

公式为:(stockPrice/stockOpenPrice)-1

如何编码此转换?

1 个答案:

答案 0 :(得分:3)

根据div使用差异iloc选择的第一列和最后一个<iframe src="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.example.com" style="width: 0px; height: 0px; margin: 0px; padding: 0px;"></iframe>

1