by.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.ffill  #

DataFrame.  ffill  (  _ *  _ , _ axis  =  None  _ , _ inplace  =  False  _ , _
limit  =  None  _ , _ limit_area  =  None  _ , _ downcast  =
_NoDefault.no_default  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/generic.py#L7484-L7606) #

    

Fill NA/NaN values by propagating the last valid observation to next valid.

Parameters  :

    

**axis** {0 or âindexâ} for Series, {0 or âindexâ, 1 or âcolumnsâ}
for DataFrame

    

Axis along which to fill missing values. For  Series  this parameter is unused
and defaults to 0.

**inplace** bool, default False

    

If True, fill in-place. Note: this will modify any other views on this object
(e.g., a no-copy slice for a column in a DataFrame).

**limit** int, default None

    

If method is specified, this is the maximum number of consecutive NaN values
to forward/backward fill. In other words, if there is a gap with more than
this number of consecutive NaNs, it will only be partially filled. If method
is not specified, this is the maximum number of entries along the entire axis
where NaNs will be filled. Must be greater than 0 if not None.

**limit_area** {  None  , âinsideâ, âoutsideâ}, default None

    

If limit is specified, consecutive NaNs will be filled with this restriction.

  * ` None  ` : No fill restriction. 

  * âinsideâ: Only fill NaNs surrounded by valid values (interpolate). 

  * âoutsideâ: Only fill NaNs outside valid values (extrapolate). 

New in version 2.2.0.

**downcast** dict, default is None

    

A dict of item->dtype of what to downcast if possible, or the string
âinferâ which will try to downcast to an appropriate equal type (e.g.
float64 to int64 if possible).

Deprecated since version 2.2.0.

Returns  :

    

Series/DataFrame or None

    

Object with missing values filled or None if ` inplace=True  ` .

Examples

    
    
    >>> df = pd.DataFrame([[np.nan, 2, np.nan, 0],
    ...                    [3, 4, np.nan, 1],
    ...                    [np.nan, np.nan, np.nan, np.nan],
    ...                    [np.nan, 3, np.nan, 4]],
    ...                   columns=list("ABCD"))
    >>> df
         A    B   C    D
    0  NaN  2.0 NaN  0.0
    1  3.0  4.0 NaN  1.0
    2  NaN  NaN NaN  NaN
    3  NaN  3.0 NaN  4.0
    
    
    
    >>> df.ffill()
         A    B   C    D
    0  NaN  2.0 NaN  0.0
    1  3.0  4.0 NaN  1.0
    2  3.0  4.0 NaN  1.0
    3  3.0  3.0 NaN  4.0
    
    
    
    >>> ser = pd.Series([1, np.nan, 2, 3])
    >>> ser.ffill()
    0   1.0
    1   1.0
    2   2.0
    3   3.0
    dtype: float64
    

[ __ previous  pandas.DataFrame.dropna  ](pandas.DataFrame.dropna.html
"previous page") [ next  pandas.DataFrame.fillna  __
](pandas.DataFrame.fillna.html "next page")

__ On this page

  * ` DataFrame.ffill()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.ffill.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.