user6412203
user6412203

Reputation:

Adding values with same frequency in time series with pandas:

I have a pandas DataFrame indexed by pandas.core.indexes.datetimes.DatetimeIndex and I'd like to add new values starting from the last date in the series. I need that each new value inserted be in the next date using a daily frequency.

Example:
            TotalOrders
Date                   
2013-12-29         3756
2013-12-30         6222
2013-12-31         4918

I'd like to insert, let's say, 5000 and that it will be automatically assigned to date 2014-01-01 and so on for the following values. What would be the best way to do that?

Example:
            TotalOrders
Date                   
2013-12-29         3756
2013-12-30         6222
2013-12-31         4918
2014-01-01         5000

Upvotes: 0

Views: 481

Answers (1)

user3483203
user3483203

Reputation: 51155

Use loc with DateOffset:

df.loc[df.index.max()+pd.DateOffset(1)] = 5000

            TotalOrders
Date
2013-12-29         3756
2013-12-30         6222
2013-12-31         4918
2014-01-01         5000

Upvotes: 4

Related Questions