In [12]:
from scipy import integrate
import numpy as np
import pandas as pd
In [9]:
x = np.abs(np.random.randn(10000))
print(x)
[ 0.66290476  1.35351935  1.47110616 ...,  1.98089506  0.4121001
  0.32761199]
In [11]:
%timeit integrate.trapz(x)
10000 loops, best of 3: 72.2 ┬Ás per loop
In [19]:
ts = pd.Series(x, pd.date_range(start='2013-05-03', periods=len(x), freq='s'))
print(ts)
2013-05-03 00:00:00    0.662905
2013-05-03 00:00:01    1.353519
2013-05-03 00:00:02    1.471106
2013-05-03 00:00:03    0.636451
2013-05-03 00:00:04    0.400131
2013-05-03 00:00:05    0.438203
2013-05-03 00:00:06    0.283670
2013-05-03 00:00:07    1.390324
2013-05-03 00:00:08    0.589401
2013-05-03 00:00:09    0.698161
2013-05-03 00:00:10    0.263194
2013-05-03 00:00:11    2.247498
2013-05-03 00:00:12    0.612423
2013-05-03 00:00:13    0.033452
2013-05-03 00:00:14    0.531537
...
2013-05-03 02:46:25    0.888961
2013-05-03 02:46:26    0.617411
2013-05-03 02:46:27    1.515751
2013-05-03 02:46:28    0.682397
2013-05-03 02:46:29    2.362538
2013-05-03 02:46:30    0.314756
2013-05-03 02:46:31    0.620458
2013-05-03 02:46:32    1.009591
2013-05-03 02:46:33    0.706764
2013-05-03 02:46:34    0.279825
2013-05-03 02:46:35    1.002564
2013-05-03 02:46:36    0.210033
2013-05-03 02:46:37    1.980895
2013-05-03 02:46:38    0.412100
2013-05-03 02:46:39    0.327612
Freq: S, Length: 10000

Integrate

In [20]:
%timeit integrate.trapz(ts, ts.index.astype(np.int64) / 10**9)
10 loops, best of 3: 58.4 ms per loop