Reputation: 904
I am trying to plot my dataset which has different dates and a variable.My dataset looks like :
Date var
2018-08-01 0.002312
2018-08-02 0.002320
2018-08-04 0.002312
2018-08-13 0.002318
2018-08-14 0.002315
Dataset has a total of 168 values and I want to predict for a period of next 30 days.
Part-1
I am trying to plot the values on the graph using the following code :
df1.pivot('Date', 'var').plot()
I am getting this error
File "pandas/_libs/hashtable_class_helper.pxi", line 1608, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Date'
Can anyone help me with the same.
Part-2
I am planning to forecast the variable var for next 30 days or so. I know that certain imputations need to be done. Can anyone advise some suggested pointers for how to impute the values and best algorithm for predicting the same.
Thanks in advance
Upvotes: 0
Views: 675
Reputation: 104
You can try this for part one:
First, we create the dataframe:
import pandas as pd
Date = ['2018-08-01', '2018-08-02', '2018-08-04', '2018-08-13']
var = [0.002312,0.002320, 0.002312, 0.002318]
frame = pd.DataFrame({'Date': Date,
'var': var})
The output looks like this:
Date var
0 2018-08-01 0.002312
1 2018-08-02 0.002320
2 2018-08-04 0.002312
3 2018-08-13 0.002318
Then we plot it with this code and imports:
import matplotlib.pyplot as plt
frame.plot('Date', 'var')
It will look like this:
Upvotes: 1