user308827
user308827

Reputation: 21961

NaNs remaining after pandas interpolate

I have the following pandas series:

0           NaN
1           NaN
2           NaN
3           NaN
4           NaN
5           NaN
6           NaN
7           NaN
8           NaN
9           NaN
10          NaN
11     2.291958
12          NaN
13          NaN
14          NaN
15          NaN
16          NaN
17          NaN
18          NaN
19          NaN
20          NaN
21          NaN
22          NaN
23          NaN
24          NaN
25          NaN
26     0.378826
27          NaN
28          NaN
29          NaN
         ...   
123         NaN
124         NaN
125         NaN
126         NaN
127    1.170094
128         NaN
129         NaN
130         NaN
131    0.008531
132         NaN
133         NaN
134         NaN
135         NaN
136         NaN
137         NaN
138         NaN
139         NaN
140         NaN
141         NaN
142         NaN
143         NaN
144         NaN
145         NaN
146         NaN
147         NaN
148         NaN
149         NaN
150         NaN
151         NaN
152         NaN
Length: 153, dtype: float64

I interpolate it as follows:

ts.interpolate(method='cubic', limit_direction='both', limit=75)

I would have expected all NaNs to be filled by this, but in the output, NaNs still remain, why is that and how can I fix it in the interpolate command?Output is as follows:

0           NaN
1           NaN
2           NaN
3           NaN
4           NaN
5           NaN
6           NaN
7           NaN
8           NaN
9           NaN
10          NaN
11     2.291958
12     1.733142
13     1.255447
14     0.854370
15     0.525409
16     0.264062
17     0.065826
18    -0.073801
19    -0.159321
20    -0.195237
21    -0.186051
22    -0.136265
23    -0.050382
24     0.067095
25     0.211666
26     0.378826
27     0.564074
28     0.762908
29     0.970824
         ...   
123    1.649933
124    1.579817
125    1.479152
126    1.343917
127    1.170094
128    0.953663
129    0.690605
130    0.376900
131    0.008531
132         NaN
133         NaN
134         NaN
135         NaN
136         NaN
137         NaN
138         NaN
139         NaN
140         NaN
141         NaN
142         NaN
143         NaN
144         NaN
145         NaN
146         NaN
147         NaN
148         NaN
149         NaN
150         NaN
151         NaN
152         NaN
Length: 153, dtype: float64

Upvotes: 1

Views: 75

Answers (1)

BENY
BENY

Reputation: 323226

I do not think cubic can do that to fillna without between , if you change the linear , it will do it

s.interpolate('linear',limit_direction='both', limit=75)
Out[62]: 
0     2.291958
1     2.291958
2     2.291958
3     2.291958
4     2.291958
5     2.291958
6     2.291958
7     2.291958
8     2.291958
9     2.291958
10    2.291958
11    2.291958
12    2.164416
13    2.036874
14    1.909332
15    1.781789
16    1.654247
17    1.526705
18    1.399163
19    1.271621
20    1.144079
21    1.016537
22    0.888995
23    0.761452
24    0.633910
25    0.506368
26    0.378826
27    0.378826
28    0.378826
29    0.378826
Name: s, dtype: float64

Upvotes: 3

Related Questions