0

I am performing a linear interpolation with a Pandas Series but it seems that it keeps replacing the NaN with the same value and I can't figure out why..

# To check where are located the missing values : 
d1[d1.isna().any(axis=1)]

             volume   price
datetime
2018-05-23 09:00:00   NaN   0.0 
2018-05-22 11:00:00   NaN   0.0 
2018-05-21 12:00:00   NaN   0.0 
2018-05-21 10:00:00   NaN   0.0 
2018-05-21 09:00:00   NaN   0.0 
2018-05-18 09:00:00   NaN   0.0 

d1["price"].astype(float).interpolate(method="time")

datetime
2018-05-23 10:00:00    23.825000
2018-05-23 09:00:00    22.425000
2018-05-22 17:00:00    24.041000
                         ...
2018-05-22 12:00:00    23.975000
2018-05-22 11:00:00    22.425000
2018-05-22 10:00:00    24.000000
                         ...
2018-05-21 12:00:00    22.425000
2018-05-21 11:00:00    23.200000
2018-05-21 10:00:00    22.425000
2018-05-21 09:00:00    22.425000
                         ...
2018-05-18 10:00:00    23.425000
2018-05-18 09:00:00    22.425000
2018-05-17 17:00:00    23.516000

The missing values are always replaced with 22.45, which is neither the mean nor the median of the Series. Could someone help ? Thanks !

EDIT : A glimpse of the initial dataframe :

                     price    volume
datetime 
2018-05-23 16:00:00  23.936667 70.0 
2018-05-23 15:00:00  24.040000 5.0 
2018-05-23 14:00:00  23.971875 185.0 
2018-05-23 13:00:00  23.811111 250.0 
2018-05-23 12:00:00  23.800000 240.0 
2018-05-23 11:00:00  23.816667 140.0 
2018-05-23 10:00:00  23.825000 10.0 
2018-05-23 09:00:00  NaN 0.0 
2018-05-22 17:00:00  24.041000 260.0 
2018-05-22 16:00:00  24.062857 150.0 
2018-05-22 15:00:00  24.031818 1525.0 
2018-05-22 14:00:00  24.079167 165.0 
2018-05-22 13:00:00  23.950000 5.0 
2018-05-22 12:00:00  23.975000 375.0 
2018-05-22 11:00:00  NaN 0.0 
2018-05-22 10:00:00  24.000000 30.0 
2018-05-22 09:00:00  24.000000 30.0 
AlexM
  • 231
  • 2
  • 13

0 Answers0