Quantcast
Channel: Replace NaNs with values from X rows earlier or later in pandas dataframe - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Replace NaNs with values from X rows earlier or later in pandas dataframe

$
0
0

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:

     ELECTRICITY0    101    152    173    124    155    166    227    88    NaN9    1610   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:

  1. fillna: only allows me to replace with a specific value or immediately adjacent values
  2. interpolate: only allows me to replace with an average of immediately adjacent values
  3. replace: seems to allow conditional replacements with set values

Thanks for any help.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images