This question is more complicated than it first appeared. I ended up using numba's jit to compile a generator function to calculate the exponential sums. My end result calculates the exponential sum of 5 million rows in under a second on my computer, which hopefully is fast enough for your needs.
# Initial dataframe.
df = pd.DataFrame({'time': [1, 2.1, 2.13, 3.7, 10, 10.2],
'A': [1, 3, -1, 7, 2, 1]})
# Initial decay parameter.
decay_constant = 1
We can define the decay weights as exp(-time_delta * decay_constant), and set its initial value equal to one:
df['weight'] = np.exp(-df.time.diff() * decay_constant)
df.weight.iat[0] = 1
>>> df
A time weight
0 1 1.00 1.000000
1 3 2.10 0.332871
2 -1 2.13 0.970446
3 7 3.70 0.208045
4 2 10.00 0.001836
5 1 10.20 0.818731
Now we'll use jit from numba to optimize a generator function that calculates the exponential sums:
from numba import jit
@jit(nopython=True)
def exponential_sum(A, k):
total = A[0]
yield total
for i in xrange(1, len(A)): # Use range in Python 3.
total = total * k[i] + A[i]
yield total
We'll use the generator to add the values to the dataframe:
df['expSum'] = list(exponential_sum(df.A.values, df.weight.values))
Which produces the desired output:
>>> df
A time weight expSum
0 1 1.00 1.000000 1.000000
1 3 2.10 0.332871 3.332871
2 -1 2.13 0.970446 2.234370
3 7 3.70 0.208045 7.464850
4 2 10.00 0.001836 2.013708
5 1 10.20 0.818731 2.648684
So let's scale to 5 million rows and check performance:
df = pd.DataFrame({'time': np.random.rand(5e6).cumsum(), 'A': np.random.randint(1, 10, 5e6)})
df['weight'] = np.exp(-df.time.diff() * decay_constant)
df.weight.iat[0] = 1
%%timeit -n 10
df['expSum'] = list(exponential_sum(df.A.values, df.weight.values))
10 loops, best of 3: 726 ms per loop