I have a dataframe, df1, which consists of entities across time and their corresponding value. df1 looks like this:
Index Date ID Values
0 2016-11-15 1 3
1 2016-11-16 1 5
2 2016-11-16 2 6
3 2016-11-17 2 7
4 2016-11-18 2 2
Obviously, there are gaps in the dates for both IDs.
I would first like to fill the date and ID gaps so it looks like this:
Index Date ID Values
0 2016-11-15 1 3
1 2016-11-16 1 5
2 2016-11-17 1 0
3 2016-11-18 1 0
4 2016-11-15 2 0
5 2016-11-16 2 6
6 2016-11-17 2 7
7 2016-11-18 2 2
Then, I want to create a lagged column for "Values" so it uses the previous day's value for each id:
Index Date ID Values Lagged Values
0 2016-11-15 1 3 Nan
1 2016-11-16 1 5 3
2 2016-11-17 1 0 5
3 2016-11-18 1 0 0
4 2016-11-15 2 0 Nan
5 2016-11-16 2 6 0
6 2016-11-17 2 7 6
7 2016-11-18 2 2 7
Thanks!