我的数据框长这样:
date time sym ask0 ask1 ask2
0 2017-08-21 07:00:00 07:00:00 7YR 100.812500 100.828125 100.843750
1 2017-08-21 07:00:15 07:00:15 7YR 100.812500 100.828125 100.843750
2 2017-08-21 07:00:30 07:00:30 7YR 100.812500 100.828125 100.843750
3 2017-08-21 07:00:45 07:00:45 7YR 100.812500 100.828125 100.843750
4 2017-08-21 07:01:00 07:01:00 7YR 100.812500 100.828125 100.843750
5 2017-08-21 07:01:15 07:01:15 7YR 100.812500 100.828125 100.843750
6 2017-08-21 07:01:30 07:01:30 7YR 100.812500 100.828125 100.843750
7 2017-08-21 07:01:45 07:01:45 7YR 100.812500 100.828125 100.843750
8 2017-08-21 07:02:00 07:02:00 7YR 100.812500 100.828125 100.843750
9 2017-08-21 07:02:15 07:02:15 7YR 100.812500 100.828125 100.843750
10 2017-08-21 07:02:30 07:02:30 7YR 100.812500 100.828125 100.843750
11 2017-08-21 07:02:45 07:02:45 7YR 100.828125 100.843750 100.859375
12 2017-08-21 07:03:00 07:03:00 7YR 100.812500 100.828125 100.843750
13 2017-08-21 07:03:15 07:03:15 7YR 100.828125 100.843750 100.859375
14 2017-08-21 07:03:30 07:03:30 7YR 100.828125 100.843750 100.859375
15 2017-08-21 07:03:45 07:03:45 7YR 100.828125 100.843750 100.859375
16 2017-08-21 07:04:00 07:04:00 7YR 100.828125 100.843750 100.859375
17 2017-08-21 07:04:15 07:04:15 7YR 100.828125 100.843750 100.859375
18 2017-08-21 07:04:30 07:04:30 7YR 100.828125 100.843750 100.859375
19 2017-08-21 07:04:45 07:04:45 7YR 100.828125 100.843750 100.859375
20 2017-08-21 07:05:00 07:05:00 7YR 100.828125 100.843750 100.859375
21 2017-08-21 07:05:15 07:05:15 7YR 100.828125 100.843750 100.859375
22 2017-08-21 07:05:30 07:05:30 7YR 100.828125 100.843750 100.859375
我想计算导数:
d = d(ask0)/dt
其中 dt = 2
分钟。
例如,
t = 2017-08-21 07:04:30 07:04:30 ask@t=100.828125
t-1 = 2017-08-21 07:04:30 07:02:30 ask@t-1=100.812500
dask/dt = (100.828125-100.812500)/2 = 0.0078125
我知道可以通过迭代数据框中的每一行来完成此操作。但我想知道是否有Pandas函数可以完成这项工作。
d['ask0'] = d['ask0']/dt
? - DJKd.ask0.diff() / dt
。 - cs95d = y2-y1 / dt
我需要一种获取y1
的方法 - Chris Johnsond.ask0.diff() / dt
将计算前一行中的差异。 - Chris Johnson