Dataframe index date adding and appending list value

Question:

Having a data frame as below:

img

The Date column is index column.I need to add a new date value and append a list value as volume.

Volume=[39]

This Volume value needs to be added to data frame.
So last value of index date+7 needs to be the first column
Expected output:

output

Date Column is index column

Can some one please help me?

Asked By: Unicorn

||

Answers:

you can use append, like so:

import datetime
# get the last row
last_date = yourDf.iloc[[-1]].index
formatted_date = datetime.datetime.strptime(last_date, "%m/%d/%y")

# add 7 days
end_date = formatted_date + datetime.timedelta(days=7)

# append data
data = {'Volume': 39}
yourDf.append(pd.DataFrame(data, index=[end_date]))
Answered By: Sudhir Bastakoti
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.