8
$\begingroup$

Since interpolate and fillna method does the same work of filling na values. What is the basic difference between the two. What is the significance of having these two different methods?? Can anyone explain me in layman terms. I already visited through the official documentation and wanted to know the difference

$\endgroup$
11
$\begingroup$

fillna fills the NaN values with a given number with which you want to substitute. It gives you an option to fill according to the index of rows of a pd.DataFrame or on the name of the columns in the form of a python dict.

But interpolate is a god in filling. It gives you the flexibility to fill the missing values with many kinds of interpolations between the values like linear (which fillna does not provide) in the example provided below and many more interpolations possible. For example

>> import pandas as pd, numpy as np
>> df = pd.Series([1, np.nan, np.nan, 3])
>> df.interpolate()
0    1.000000
1    1.666667
2    2.333333
3    3.000000
dtype: float64

Pandas documentation on fillna and interpolate is very clear on this.

$\endgroup$
  • $\begingroup$ Understood. Suppose if i want to fill only some specific values(may be in range or without range) that can also be done using interpolation. Right ? $\endgroup$ – Siddhesh Kalgaonkar Dec 23 '17 at 17:23
  • $\begingroup$ Is it filling in with specific values or filling specific values as in cells of a DataFrame? $\endgroup$ – Kiritee Gak Dec 24 '17 at 0:30
  • $\begingroup$ filling specific values in cell at some particular locations only but at a time many values should be filled or in some range $\endgroup$ – Siddhesh Kalgaonkar Dec 24 '17 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.