Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

pandas

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?

like image 692
jhourback Avatar asked Sep 08 '25 14:09

jhourback


1 Answers

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

like image 155
piRSquared Avatar answered Sep 10 '25 05:09

piRSquared