Having a data frame as below:
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:
Date Column is index column
Can some one please help me?
CodePudding user response:
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]))