I have a pandas dataframe that looks like this:
AAPL IBM GOOG XOM
2011-01-10 16:00:00 1500 0 0 0
2011-01-11 16:00:00 0 0 0 0
2011-01-12 16:00:00 0 0 0 0
2011-01-13 16:00:00 -1500 4000 0 0
2011-01-14 16:00:00 0 0 0 0
2011-01-18 16:00:00 0 0 0 0
My goal is to fill the rows by adding the previous row values. The result would look like this:
AAPL IBM GOOG XOM
2011-01-10 16:00:00 1500 0 0 0
2011-01-11 16:00:00 1500 0 0 0
2011-01-12 16:00:00 1500 0 0 0
2011-01-13 16:00:00 0 4000 0 0
2011-01-14 16:00:00 0 4000 0 0
2011-01-18 16:00:00 0 4000 0 0
I tried to iterate through the dataframe index with
for date in df.index:
and to increment dates with
dt_nextDate = date + dt.timedelta(days=1)
but there are gaps in the dataframe index that stand for weekends.
Can I iterate through the index from the second row to the end, refer back to the previous row and add the values?