jhourback
jhourback

Reputation: 4571

In fillna, what is the difference between pad and ffill method?

In fillna, the arguments method='pad' and method='ffill' appear to give the same behavior. Is there any difference? Is one method preferable to the other?

Upvotes: 4

Views: 7151

Answers (1)

piRSquared
piRSquared

Reputation: 294338

pandas.DataFrame.fillna

They are the same. I like 'ffill' because it's more descriptive of what it does.


We can see in the source for the generic NDFRame.fillna
source

    method = missing.clean_fill_method(method)

Where we can see that when method == 'ffill' it gets swapped for 'pad'
source

    if method == 'ffill':
        method = 'pad'

Note
pandas also has a ffill method that does the same thing

Upvotes: 11

Related Questions