I'm trying to efficiently compute a running sum, with exponential decay, of each column of a Pandas DataFrame. The DataFrame contains a daily score for each country in the world. The DataFrame looks like this:
AF UK US
2014-07-01 0.998042 0.595720 0.524698
2014-07-02 0.380649 0.838436 0.355149
2014-07-03 0.306240 0.274755 0.964524
2014-07-04 0.396721 0.836027 0.225848
2014-07-05 0.151291 0.677794 0.603548
2014-07-06 0.558846 0.050535 0.551785
2014-07-07 0.463514 0.552748 0.265537
2014-07-08 0.240282 0.278825 0.116432
2014-07-09 0.309446 0.096573 0.246021
2014-07-10 0.800977 0.583496 0.713893
I'm not sure how to calculate the rolling sum (with decay) without iterating through the dataframe, since I need to know yesterday's score to calculate today's score. But to calculate yesterday's score, I need to know the day before yesterday's score, etc. This is the code that I've been using, but I'd like a more efficient way to go about it.
for j, val in df.iteritems():
for i, row in enumerate(val):
df[j].iloc[i] = row + val[i-1]*np.exp(-0.05)