I have the following dataset:
data = {
'date': ['1/1/2019', '1/2/2019', '1/3/2019', '1/4/2019', '1/1/2019', '1/2/2019', '1/3/2019', '1/4/2019'],
'account_id': [1, 1, 1, 1, 2, 2, 2, 2],
'value_1': [1, 2, 3, 4, 5, 6, 7, 8],
'value_2': [1, 3, 6, 9, 10, 12, 14, 16]
}
df = pd.DataFrame(data,index = data['date']).drop('date', 1)
df
What I need is to extrapolate value 1 and value 2 forward by 30 days.
I came across Extrapolate Pandas DataFrame. It would work beautifully if there were no duplicated entries in the date column.
I thought of using sth of this sort but I don't understand how to add v to the function:
def extrapolation(df):
extend = 1
y = pd.DataFrame(
data=df,
index=pd.date_range(
start=df.index[0],
periods=len(df.index) + extend
)
)
#then, the extrapolation piece
df_out=df.head(0).copy()
for k,v in df.groupby('account_id'):
df_out=pd.concat([df_out,extrapolation(df)])