Reputation: 3
I have a Dataframe in which each row represents a consecutive day and the column represents total electricity consumption. There are some NaN values where data is missing:
ELECTRICITY
0 10
1 15
2 17
3 12
4 15
5 16
6 22
7 8
8 NaN
9 16
10 13
Because electricity consumption in this sample is mostly affected by day of the week, I want to replace all NaNs with the value from 7 rows earlier or later.
I have investigated the following with no success:
Thanks for any help.
Upvotes: 0
Views: 62
Reputation: 294506
Use fillna
and shift
df.fillna(df.shift(7))
ELECTRICITY
0 10.0
1 15.0
2 17.0
3 12.0
4 15.0
5 16.0
6 22.0
7 8.0
8 15.0
9 16.0
10 13.0
Upvotes: 1